v2.0.t2
Logs are not rotating correctly. Changed up the code to append the logs in memory and then dump them to permanent storage on every loop of upkeep(). Hopefully this fixes the issue.
This commit is contained in:
parent
a065b7a1d3
commit
b0dbfa0852
|
@ -138,17 +138,20 @@ void enforceMaxEvents(shared_t *share)
|
|||
|
||||
while (names.size() > share->maxEvents)
|
||||
{
|
||||
// removes the playlist file extension.
|
||||
auto nameOnly = names[0].substr(0, names[0].size() - 5);
|
||||
auto imgFile = nameOnly + ".jpg";
|
||||
auto webFile = nameOnly + ".html";
|
||||
if (names[0] != "stream.m3u8")
|
||||
{
|
||||
// removes the playlist file extension.
|
||||
auto nameOnly = names[0].substr(0, names[0].size() - 5);
|
||||
auto imgFile = nameOnly + ".jpg";
|
||||
auto webFile = nameOnly + ".html";
|
||||
|
||||
cleanupStream(names[0]);
|
||||
remove(names[0]);
|
||||
|
||||
if (exists(imgFile)) remove(imgFile);
|
||||
if (exists(webFile)) remove(webFile);
|
||||
cleanupStream(names[0]);
|
||||
remove(names[0]);
|
||||
|
||||
if (exists(imgFile)) remove(imgFile);
|
||||
if (exists(webFile)) remove(webFile);
|
||||
}
|
||||
|
||||
names.erase(names.begin());
|
||||
}
|
||||
}
|
||||
|
@ -220,13 +223,11 @@ bool rdConf(const string &filePath, shared_t *share)
|
|||
rdLine("web_font = ", line, &share->webFont);
|
||||
rdLine("sch_sec = ", line, &share->schSec);
|
||||
rdLine("post_cmd = ", line, &share->postCmd);
|
||||
rdLine("frame_gap = ", line, &share->frameGap);
|
||||
rdLine("pix_thresh = ", line, &share->pixThresh);
|
||||
rdLine("img_thresh = ", line, &share->imgThresh);
|
||||
rdLine("max_days = ", line, &share->maxDays);
|
||||
rdLine("max_events = ", line, &share->maxEvents);
|
||||
rdLine("max_log_size = ", line, &share->maxLogSize);
|
||||
rdLine("vid_codec = ", line, &share->vidCodec);
|
||||
}
|
||||
|
||||
} while(!line.empty());
|
||||
|
@ -240,24 +241,16 @@ bool rdConf(shared_t *share)
|
|||
share->recordUrl.clear();
|
||||
share->postCmd.clear();
|
||||
share->camName.clear();
|
||||
share->recLogPath.clear();
|
||||
share->detLogPath.clear();
|
||||
share->upkLogPath.clear();
|
||||
share->recLogFile.close();
|
||||
share->detLogFile.close();
|
||||
share->upkLogFile.close();
|
||||
|
||||
share->retCode = 0;
|
||||
share->frameGap = 20;
|
||||
share->pixThresh = 150;
|
||||
share->imgThresh = 80000;
|
||||
share->pixThresh = 50;
|
||||
share->imgThresh = 800;
|
||||
share->maxDays = 15;
|
||||
share->maxEvents = 20;
|
||||
share->maxLogSize = 50000;
|
||||
share->skipCmd = false;
|
||||
share->schSec = 60;
|
||||
share->webRoot = "/var/www/html";
|
||||
share->vidCodec = "copy";
|
||||
share->webBg = "#485564";
|
||||
share->webTxt = "#dee5ee";
|
||||
share->webFont = "courier";
|
||||
|
@ -269,10 +262,7 @@ bool rdConf(shared_t *share)
|
|||
share->camName = path(share->conf).filename();
|
||||
}
|
||||
|
||||
share->outDir = cleanDir(share->webRoot) + "/" + share->camName;
|
||||
share->recLogPath = share->outDir + "/rec_log_lines.html";
|
||||
share->detLogPath = share->outDir + "/det_log_lines.html";
|
||||
share->upkLogPath = share->outDir + "/upk_log_lines.html";
|
||||
share->outDir = cleanDir(share->webRoot) + "/" + share->camName;
|
||||
|
||||
error_code ec;
|
||||
|
||||
|
|
17
src/common.h
17
src/common.h
|
@ -37,8 +37,11 @@ using namespace std;
|
|||
using namespace std::filesystem;
|
||||
using namespace std::chrono;
|
||||
|
||||
#define APP_VER "2.0.t1"
|
||||
#define APP_NAME "Motion Watch"
|
||||
#define APP_VER "2.0.t2"
|
||||
#define APP_NAME "Motion Watch"
|
||||
#define REC_LOG_NAME "rec_log_lines.html"
|
||||
#define DET_LOG_NAME "det_log_lines.html"
|
||||
#define UPK_LOG_NAME "upk_log_lines.html"
|
||||
|
||||
struct pls_t
|
||||
{
|
||||
|
@ -53,17 +56,13 @@ struct pls_t
|
|||
struct shared_t
|
||||
{
|
||||
vector<pls_t> recList;
|
||||
ofstream recLogFile;
|
||||
ofstream detLogFile;
|
||||
ofstream upkLogFile;
|
||||
string conf;
|
||||
string recLogPath;
|
||||
string detLogPath;
|
||||
string upkLogPath;
|
||||
string recLog;
|
||||
string detLog;
|
||||
string upkLog;
|
||||
string recordUrl;
|
||||
string outDir;
|
||||
string postCmd;
|
||||
string vidCodec;
|
||||
string camName;
|
||||
string webBg;
|
||||
string webTxt;
|
||||
|
|
|
@ -14,17 +14,17 @@
|
|||
|
||||
void recLog(const string &line, shared_t *share)
|
||||
{
|
||||
share->recLogFile << genTimeStr("[%Y-%m-%d-%H-%M-%S] ") << line << "<br>" << endl;
|
||||
share->recLog += genTimeStr("[%Y-%m-%d-%H-%M-%S] ") + line + "<br>\n";
|
||||
}
|
||||
|
||||
void detLog(const string &line, shared_t *share)
|
||||
{
|
||||
share->detLogFile << genTimeStr("[%Y-%m-%d-%H-%M-%S] ") << line << "<br>" << endl;
|
||||
share->detLog += genTimeStr("[%Y-%m-%d-%H-%M-%S] ") + line + "<br>\n";
|
||||
}
|
||||
|
||||
void upkLog(const string &line, shared_t *share)
|
||||
{
|
||||
share->upkLogFile << genTimeStr("[%Y-%m-%d-%H-%M-%S] ") << line << "<br>" << endl;
|
||||
share->upkLog += genTimeStr("[%Y-%m-%d-%H-%M-%S] ") + line + "<br>\n";
|
||||
}
|
||||
|
||||
void enforceMaxLogSize(const string &filePath, shared_t *share)
|
||||
|
@ -38,16 +38,24 @@ void enforceMaxLogSize(const string &filePath, shared_t *share)
|
|||
}
|
||||
}
|
||||
|
||||
void initLogFile(const string &filePath, ofstream &fileObj)
|
||||
void dumpLogs(const char *fileName, const string &lines)
|
||||
{
|
||||
if (!fileObj.is_open())
|
||||
if (!lines.empty())
|
||||
{
|
||||
if (!exists(filePath))
|
||||
ofstream outFile;
|
||||
|
||||
if (exists(fileName))
|
||||
{
|
||||
system(string("touch " + filePath).c_str());
|
||||
outFile.open(fileName, ofstream::app);
|
||||
}
|
||||
else
|
||||
{
|
||||
outFile.open(fileName);
|
||||
}
|
||||
|
||||
fileObj.open(filePath.c_str(), ofstream::app | ofstream::out);
|
||||
outFile << lines;
|
||||
|
||||
outFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,11 +116,7 @@ void initLogFrontPage(const string &filePath, const string &logLinesFile)
|
|||
|
||||
void initLogFrontPages(shared_t *share)
|
||||
{
|
||||
auto recLogFilePath = share->outDir + "/recording_log.html";
|
||||
auto detLogFilePath = share->outDir + "/detection_log.html";
|
||||
auto upkLogFilePath = share->outDir + "/upkeep_log.html";
|
||||
|
||||
initLogFrontPage(recLogFilePath, path(share->recLogPath).filename().string());
|
||||
initLogFrontPage(detLogFilePath, path(share->detLogPath).filename().string());
|
||||
initLogFrontPage(upkLogFilePath, path(share->upkLogPath).filename().string());
|
||||
initLogFrontPage("recording_log.html", REC_LOG_NAME);
|
||||
initLogFrontPage("detection_log.html", DET_LOG_NAME);
|
||||
initLogFrontPage("upkeep_log.html", UPK_LOG_NAME);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
void recLog(const string &line, shared_t *share);
|
||||
void detLog(const string &line, shared_t *share);
|
||||
void upkLog(const string &line, shared_t *share);
|
||||
void dumpLogs(const char *fileName, const string &lines);
|
||||
void enforceMaxLogSize(const string &filePath, shared_t *share);
|
||||
void initLogFile(const string &filePath, ofstream &fileObj);
|
||||
void initLogFrontPages(shared_t *share);
|
||||
|
||||
#endif // lOGGER_H
|
||||
|
|
19
src/main.cpp
19
src/main.cpp
|
@ -93,13 +93,17 @@ void upkeep(shared_t *share)
|
|||
{
|
||||
while (share->retCode == 0)
|
||||
{
|
||||
enforceMaxLogSize(share->recLogPath, share);
|
||||
enforceMaxLogSize(share->detLogPath, share);
|
||||
enforceMaxLogSize(share->upkLogPath, share);
|
||||
enforceMaxLogSize(REC_LOG_NAME, share);
|
||||
enforceMaxLogSize(DET_LOG_NAME, share);
|
||||
enforceMaxLogSize(UPK_LOG_NAME, share);
|
||||
|
||||
initLogFile(share->recLogPath, share->recLogFile);
|
||||
initLogFile(share->detLogPath, share->detLogFile);
|
||||
initLogFile(share->upkLogPath, share->upkLogFile);
|
||||
dumpLogs(REC_LOG_NAME, share->recLog);
|
||||
dumpLogs(DET_LOG_NAME, share->detLog);
|
||||
dumpLogs(UPK_LOG_NAME, share->upkLog);
|
||||
|
||||
share->recLog.clear();
|
||||
share->detLog.clear();
|
||||
share->upkLog.clear();
|
||||
|
||||
initLogFrontPages(share);
|
||||
enforceMaxEvents(share);
|
||||
|
@ -137,8 +141,7 @@ void recLoop(shared_t *share)
|
|||
" -strftime 1" +
|
||||
" -strftime_mkdir 1" +
|
||||
" -hls_segment_filename 'VIDEO_TS/live/%Y/%j/%H/%M%S.ts'" +
|
||||
" -y -vcodec " +
|
||||
share->vidCodec +
|
||||
" -y -vcodec copy" +
|
||||
" -f hls -hls_time 6 -hls_list_size " +
|
||||
to_string((share->maxDays * 86400) / 6) + // 86400 seconds in a day.
|
||||
" stream.m3u8";
|
||||
|
|
Loading…
Reference in New Issue
Block a user