ClassLogFile.cpp 843 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "ClassLogFile.h"
  2. #include "time_sntp.h"
  3. ClassLogFile LogFile("/sdcard/log.txt");
  4. void ClassLogFile::WriteToDedicatedFile(std::string _fn, std::string info, bool _time)
  5. {
  6. FILE* pFile;
  7. std::string zwtime;
  8. pFile = fopen(_fn.c_str(), "a+");
  9. if (_time)
  10. {
  11. time_t rawtime;
  12. struct tm* timeinfo;
  13. char buffer[80];
  14. time(&rawtime);
  15. timeinfo = localtime(&rawtime);
  16. strftime(buffer, 80, "%Y-%m-%d_%H-%M-%S", timeinfo);
  17. zwtime = std::string(buffer);
  18. info = zwtime + ": " + info;
  19. }
  20. fputs(info.c_str(), pFile);
  21. fputs("\n", pFile);
  22. fclose(pFile);
  23. }
  24. void ClassLogFile::WriteToFile(std::string info, bool _time)
  25. {
  26. WriteToDedicatedFile(logfile, info, _time);
  27. }
  28. ClassLogFile::ClassLogFile(std::string _logfile)
  29. {
  30. logfile = _logfile;
  31. }