SystemLogMessage.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "Module_OcppBackend.h"
  2. int StoreLogMsg(const char *fmt, ...)
  3. {
  4. char Buf[65536+256];
  5. char buffer[65536];
  6. //char Buf[4096+256];
  7. //char buffer[4096];
  8. time_t CurrentTime;
  9. struct tm *tm;
  10. va_list args;
  11. va_start(args, fmt);
  12. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  13. va_end(args);
  14. memset(Buf,0,sizeof(Buf));
  15. CurrentTime = time(NULL);
  16. tm=localtime(&CurrentTime);
  17. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/OCPP/[%04d.%02d]SystemLog",
  18. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
  19. buffer,
  20. tm->tm_year+1900,tm->tm_mon+1);
  21. //printf("buffer: %s\n",Buf );
  22. //execl("sh", "sh", "-c", Buf, NULL);//system((const char*)Buf);
  23. system((const char*)Buf);
  24. #ifdef ConsloePrintLog
  25. 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);
  26. #endif
  27. return rc;
  28. }
  29. int StoreOcppMsg(const char *fmt, ...)
  30. {
  31. char Buf[65536+256];
  32. char buffer[65536];
  33. //char Buf[4096+256];
  34. //char buffer[4096];
  35. time_t CurrentTime;
  36. struct tm *tm;
  37. va_list args;
  38. va_start(args, fmt);
  39. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  40. va_end(args);
  41. memset(Buf,0,sizeof(Buf));
  42. CurrentTime = time(NULL);
  43. tm=localtime(&CurrentTime);
  44. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/OCPP/[%04d.%02d]OcppMessage",
  45. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
  46. buffer,
  47. tm->tm_year+1900,tm->tm_mon+1);
  48. //printf("buffer: %s\n",Buf );
  49. //execl("sh", "sh", "-c", Buf, NULL);//system((const char*)Buf);
  50. system((const char*)Buf);
  51. #ifdef ConsloePrintLog
  52. 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);
  53. #endif
  54. return rc;
  55. }