SystemLogMessage.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\" >> /Storage/OCPP/[%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. 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. int StoreOcppMsg(const char *fmt, ...)
  37. {
  38. char Buf[4096+256];
  39. char buffer[4096];
  40. time_t CurrentTime;
  41. struct tm *tm;
  42. va_list args;
  43. va_start(args, fmt);
  44. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  45. va_end(args);
  46. memset(Buf,0,sizeof(Buf));
  47. CurrentTime = time(NULL);
  48. tm=localtime(&CurrentTime);
  49. sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/OCPP/[%04d.%02d]OcppMessage",
  50. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
  51. buffer,
  52. tm->tm_year+1900,tm->tm_mon+1);
  53. //printf("buffer: %s\n",Buf );
  54. //execl("sh", "sh", "-c", Buf, NULL);//system((const char*)Buf);
  55. system((const char*)Buf);
  56. #ifdef Debug
  57. 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);
  58. #endif
  59. return rc;
  60. }
  61. #endif