SystemLogMessage.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "SystemLogMessage.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <stdarg.h>
  7. #include <unistd.h>
  8. //#include "SystemLogMessage.h"
  9. #define Debug
  10. #define SystemLogMessage
  11. #ifdef SystemLogMessage
  12. int StoreLogMsg(const char *fmt, ...)
  13. {
  14. char Buf[4096+256];
  15. char buffer[4096];
  16. time_t CurrentTime;
  17. struct tm *tm;
  18. va_list args;
  19. va_start(args, fmt);
  20. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  21. va_end(args);
  22. memset(Buf,0,sizeof(Buf));
  23. CurrentTime = time(NULL);
  24. tm=localtime(&CurrentTime);
  25. sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> SystemLog/[%04d.%02d]SystemLog",
  26. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
  27. buffer,
  28. tm->tm_year+1900,tm->tm_mon+1);
  29. printf("buffer: %s\n",Buf );
  30. execl("sh", "sh", "-c", Buf, NULL);//system((const char*)Buf);
  31. #ifdef Debug
  32. printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
  33. #endif
  34. return rc;
  35. }
  36. #endif