You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectFileLoggingService.h"
  2. objectFileLoggingService::objectFileLoggingService(const char * FileName)
  3. {
  4. memset(m_pFileName, 0, MAX_PATH_LEN);
  5. strncpy(m_pFileName, FileName, MAX_PATH_LEN - 1);
  6. m_bLogging = true;
  7. }
  8. objectFileLoggingService::objectFileLoggingService(CSTR FileName)
  9. {
  10. memset(m_pFileName, 0, MAX_PATH_LEN);
  11. strncpy(m_pFileName, FileName, MAX_PATH_LEN - 1);
  12. m_bLogging = true;
  13. }
  14. void objectFileLoggingService::logMessage(CSTR Msg)
  15. {
  16. logMessage((const char *) Msg);
  17. }
  18. void objectFileLoggingService::logMessage(const char * Msg)
  19. {
  20. if (m_bLogging)
  21. {
  22. if (getFileSize(m_pFileName) > MAX_LOG_FILE_SIZE)
  23. {
  24. if (MAX_LOG_FILE_BACKUPS)
  25. {
  26. char tB[2048];
  27. sprintf(tB, "%s.%d", m_pFileName, MAX_LOG_FILE_BACKUPS);
  28. if (fileExist(tB))
  29. {
  30. unlink(tB);
  31. }
  32. uint8_t ix = MAX_LOG_FILE_BACKUPS;
  33. while (ix)
  34. {
  35. char tZ[2048];
  36. sprintf(tZ, "%s.%d", m_pFileName, ix);
  37. if (ix - 1)
  38. {
  39. sprintf(tB, "%s.%d", m_pFileName, ix - 1);
  40. }
  41. else
  42. {
  43. sprintf(tB, "%s", m_pFileName);
  44. };
  45. if (fileExist(tB))
  46. {
  47. rename(tB, tZ);
  48. }
  49. ix--;
  50. };
  51. }
  52. else
  53. {
  54. unlink(m_pFileName);
  55. };
  56. };
  57. FILE * FD;
  58. FD = fopen(m_pFileName, "a+");
  59. if (FD != NULL)
  60. {
  61. fwrite(Msg, 1, strlen(Msg), FD);
  62. fclose(FD);
  63. };
  64. };
  65. }