SystemLogMessage.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <sys/time.h>
  2. #include <sys/timeb.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/socket.h>
  8. #include <sys/ipc.h>
  9. #include <sys/shm.h>
  10. #include <sys/shm.h>
  11. #include <sys/mman.h>
  12. #include <linux/wireless.h>
  13. #include <arpa/inet.h>
  14. #include <netinet/in.h>
  15. #include <unistd.h>
  16. #include <stdarg.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. #include <fcntl.h>
  21. #include <termios.h>
  22. #include <errno.h>
  23. #include <errno.h>
  24. #include <string.h>
  25. #include <time.h>
  26. #include <ctype.h>
  27. #include <ifaddrs.h>
  28. #include <signal.h>
  29. #include "SystemLogMessage.h"
  30. /**
  31. * Output debug info
  32. * @param fmt
  33. * @return
  34. */
  35. int StoreLogMsg(const char *fmt, ...)
  36. {
  37. char Buf[4096+256];
  38. char buffer[4096];
  39. time_t CurrentTime;
  40. struct tm *tm;
  41. va_list args;
  42. va_start(args, fmt);
  43. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  44. va_end(args);
  45. memset(Buf,0,sizeof(Buf));
  46. CurrentTime = time(NULL);
  47. tm=localtime(&CurrentTime);
  48. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]Module_DcMeterLog",
  49. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
  50. buffer,
  51. tm->tm_year+1900,tm->tm_mon+1);
  52. system(Buf);
  53. #ifdef ConsloePrintLog
  54. 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);
  55. #endif
  56. return rc;
  57. }