Files
AI-on-the-edge-device/code/lib/jomjol_logfile/ClassLogFile.cpp
2020-09-25 08:42:45 +02:00

51 lines
992 B
C++

#include "ClassLogFile.h"
#include "time_sntp.h"
ClassLogFile LogFile("/sdcard/log.txt");
void ClassLogFile::WriteToDedicatedFile(std::string _fn, std::string info, bool _time)
{
FILE* pFile;
std::string zwtime;
if (!doLogFile){
return;
}
pFile = fopen(_fn.c_str(), "a+");
if (_time)
{
time_t rawtime;
struct tm* timeinfo;
char buffer[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 80, "%Y-%m-%d_%H-%M-%S", timeinfo);
zwtime = std::string(buffer);
info = zwtime + ": " + info;
}
fputs(info.c_str(), pFile);
fputs("\n", pFile);
fclose(pFile);
}
void ClassLogFile::SwitchOnOff(bool _doLogFile){
doLogFile = _doLogFile;
};
void ClassLogFile::WriteToFile(std::string info, bool _time)
{
WriteToDedicatedFile(logfile, info, _time);
}
ClassLogFile::ClassLogFile(std::string _logfile)
{
logfile = _logfile;
doLogFile = true;
}