SystemLogMessage.c 1.0 KB

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