SystemLogMessage.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "SystemLogMessage.h"
  29. int StoreLogMsg(const char *fmt, ...)
  30. {
  31. char Buf[4096+256];
  32. char buffer[4096];
  33. time_t CurrentTime;
  34. struct tm *tm;
  35. struct timeval tv;
  36. va_list args;
  37. va_start(args, fmt);
  38. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  39. va_end(args);
  40. memset(Buf,0,sizeof(Buf));
  41. CurrentTime = time(NULL);
  42. tm=localtime(&CurrentTime);
  43. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  44. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]CCS_SystemLog",
  45. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
  46. buffer,
  47. tm->tm_year+1900,tm->tm_mon+1);
  48. #ifdef SystemLogMessage
  49. system((const char*)Buf);
  50. #endif
  51. #ifdef ConsloePrintLog
  52. printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
  53. #endif
  54. return rc;
  55. }