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)
|
while (names.size() > share->maxEvents)
|
||||||
{
|
{
|
||||||
// removes the playlist file extension.
|
if (names[0] != "stream.m3u8")
|
||||||
auto nameOnly = names[0].substr(0, names[0].size() - 5);
|
{
|
||||||
auto imgFile = nameOnly + ".jpg";
|
// removes the playlist file extension.
|
||||||
auto webFile = nameOnly + ".html";
|
auto nameOnly = names[0].substr(0, names[0].size() - 5);
|
||||||
|
auto imgFile = nameOnly + ".jpg";
|
||||||
|
auto webFile = nameOnly + ".html";
|
||||||
|
|
||||||
cleanupStream(names[0]);
|
cleanupStream(names[0]);
|
||||||
remove(names[0]);
|
remove(names[0]);
|
||||||
|
|
||||||
if (exists(imgFile)) remove(imgFile);
|
|
||||||
if (exists(webFile)) remove(webFile);
|
|
||||||
|
|
||||||
|
if (exists(imgFile)) remove(imgFile);
|
||||||
|
if (exists(webFile)) remove(webFile);
|
||||||
|
}
|
||||||
|
|
||||||
names.erase(names.begin());
|
names.erase(names.begin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,13 +223,11 @@ bool rdConf(const string &filePath, shared_t *share)
|
||||||
rdLine("web_font = ", line, &share->webFont);
|
rdLine("web_font = ", line, &share->webFont);
|
||||||
rdLine("sch_sec = ", line, &share->schSec);
|
rdLine("sch_sec = ", line, &share->schSec);
|
||||||
rdLine("post_cmd = ", line, &share->postCmd);
|
rdLine("post_cmd = ", line, &share->postCmd);
|
||||||
rdLine("frame_gap = ", line, &share->frameGap);
|
|
||||||
rdLine("pix_thresh = ", line, &share->pixThresh);
|
rdLine("pix_thresh = ", line, &share->pixThresh);
|
||||||
rdLine("img_thresh = ", line, &share->imgThresh);
|
rdLine("img_thresh = ", line, &share->imgThresh);
|
||||||
rdLine("max_days = ", line, &share->maxDays);
|
rdLine("max_days = ", line, &share->maxDays);
|
||||||
rdLine("max_events = ", line, &share->maxEvents);
|
rdLine("max_events = ", line, &share->maxEvents);
|
||||||
rdLine("max_log_size = ", line, &share->maxLogSize);
|
rdLine("max_log_size = ", line, &share->maxLogSize);
|
||||||
rdLine("vid_codec = ", line, &share->vidCodec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} while(!line.empty());
|
} while(!line.empty());
|
||||||
|
@ -240,24 +241,16 @@ bool rdConf(shared_t *share)
|
||||||
share->recordUrl.clear();
|
share->recordUrl.clear();
|
||||||
share->postCmd.clear();
|
share->postCmd.clear();
|
||||||
share->camName.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->retCode = 0;
|
||||||
share->frameGap = 20;
|
share->pixThresh = 50;
|
||||||
share->pixThresh = 150;
|
share->imgThresh = 800;
|
||||||
share->imgThresh = 80000;
|
|
||||||
share->maxDays = 15;
|
share->maxDays = 15;
|
||||||
share->maxEvents = 20;
|
share->maxEvents = 20;
|
||||||
share->maxLogSize = 50000;
|
share->maxLogSize = 50000;
|
||||||
share->skipCmd = false;
|
share->skipCmd = false;
|
||||||
share->schSec = 60;
|
share->schSec = 60;
|
||||||
share->webRoot = "/var/www/html";
|
share->webRoot = "/var/www/html";
|
||||||
share->vidCodec = "copy";
|
|
||||||
share->webBg = "#485564";
|
share->webBg = "#485564";
|
||||||
share->webTxt = "#dee5ee";
|
share->webTxt = "#dee5ee";
|
||||||
share->webFont = "courier";
|
share->webFont = "courier";
|
||||||
|
@ -269,10 +262,7 @@ bool rdConf(shared_t *share)
|
||||||
share->camName = path(share->conf).filename();
|
share->camName = path(share->conf).filename();
|
||||||
}
|
}
|
||||||
|
|
||||||
share->outDir = cleanDir(share->webRoot) + "/" + share->camName;
|
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";
|
|
||||||
|
|
||||||
error_code ec;
|
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::filesystem;
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
||||||
#define APP_VER "2.0.t1"
|
#define APP_VER "2.0.t2"
|
||||||
#define APP_NAME "Motion Watch"
|
#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
|
struct pls_t
|
||||||
{
|
{
|
||||||
|
@ -53,17 +56,13 @@ struct pls_t
|
||||||
struct shared_t
|
struct shared_t
|
||||||
{
|
{
|
||||||
vector<pls_t> recList;
|
vector<pls_t> recList;
|
||||||
ofstream recLogFile;
|
|
||||||
ofstream detLogFile;
|
|
||||||
ofstream upkLogFile;
|
|
||||||
string conf;
|
string conf;
|
||||||
string recLogPath;
|
string recLog;
|
||||||
string detLogPath;
|
string detLog;
|
||||||
string upkLogPath;
|
string upkLog;
|
||||||
string recordUrl;
|
string recordUrl;
|
||||||
string outDir;
|
string outDir;
|
||||||
string postCmd;
|
string postCmd;
|
||||||
string vidCodec;
|
|
||||||
string camName;
|
string camName;
|
||||||
string webBg;
|
string webBg;
|
||||||
string webTxt;
|
string webTxt;
|
||||||
|
|
|
@ -14,17 +14,17 @@
|
||||||
|
|
||||||
void recLog(const string &line, shared_t *share)
|
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)
|
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)
|
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)
|
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)
|
void initLogFrontPages(shared_t *share)
|
||||||
{
|
{
|
||||||
auto recLogFilePath = share->outDir + "/recording_log.html";
|
initLogFrontPage("recording_log.html", REC_LOG_NAME);
|
||||||
auto detLogFilePath = share->outDir + "/detection_log.html";
|
initLogFrontPage("detection_log.html", DET_LOG_NAME);
|
||||||
auto upkLogFilePath = share->outDir + "/upkeep_log.html";
|
initLogFrontPage("upkeep_log.html", UPK_LOG_NAME);
|
||||||
|
|
||||||
initLogFrontPage(recLogFilePath, path(share->recLogPath).filename().string());
|
|
||||||
initLogFrontPage(detLogFilePath, path(share->detLogPath).filename().string());
|
|
||||||
initLogFrontPage(upkLogFilePath, path(share->upkLogPath).filename().string());
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
void recLog(const string &line, shared_t *share);
|
void recLog(const string &line, shared_t *share);
|
||||||
void detLog(const string &line, shared_t *share);
|
void detLog(const string &line, shared_t *share);
|
||||||
void upkLog(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 enforceMaxLogSize(const string &filePath, shared_t *share);
|
||||||
void initLogFile(const string &filePath, ofstream &fileObj);
|
|
||||||
void initLogFrontPages(shared_t *share);
|
void initLogFrontPages(shared_t *share);
|
||||||
|
|
||||||
#endif // lOGGER_H
|
#endif // lOGGER_H
|
||||||
|
|
19
src/main.cpp
19
src/main.cpp
|
@ -93,13 +93,17 @@ void upkeep(shared_t *share)
|
||||||
{
|
{
|
||||||
while (share->retCode == 0)
|
while (share->retCode == 0)
|
||||||
{
|
{
|
||||||
enforceMaxLogSize(share->recLogPath, share);
|
enforceMaxLogSize(REC_LOG_NAME, share);
|
||||||
enforceMaxLogSize(share->detLogPath, share);
|
enforceMaxLogSize(DET_LOG_NAME, share);
|
||||||
enforceMaxLogSize(share->upkLogPath, share);
|
enforceMaxLogSize(UPK_LOG_NAME, share);
|
||||||
|
|
||||||
initLogFile(share->recLogPath, share->recLogFile);
|
dumpLogs(REC_LOG_NAME, share->recLog);
|
||||||
initLogFile(share->detLogPath, share->detLogFile);
|
dumpLogs(DET_LOG_NAME, share->detLog);
|
||||||
initLogFile(share->upkLogPath, share->upkLogFile);
|
dumpLogs(UPK_LOG_NAME, share->upkLog);
|
||||||
|
|
||||||
|
share->recLog.clear();
|
||||||
|
share->detLog.clear();
|
||||||
|
share->upkLog.clear();
|
||||||
|
|
||||||
initLogFrontPages(share);
|
initLogFrontPages(share);
|
||||||
enforceMaxEvents(share);
|
enforceMaxEvents(share);
|
||||||
|
@ -137,8 +141,7 @@ void recLoop(shared_t *share)
|
||||||
" -strftime 1" +
|
" -strftime 1" +
|
||||||
" -strftime_mkdir 1" +
|
" -strftime_mkdir 1" +
|
||||||
" -hls_segment_filename 'VIDEO_TS/live/%Y/%j/%H/%M%S.ts'" +
|
" -hls_segment_filename 'VIDEO_TS/live/%Y/%j/%H/%M%S.ts'" +
|
||||||
" -y -vcodec " +
|
" -y -vcodec copy" +
|
||||||
share->vidCodec +
|
|
||||||
" -f hls -hls_time 6 -hls_list_size " +
|
" -f hls -hls_time 6 -hls_list_size " +
|
||||||
to_string((share->maxDays * 86400) / 6) + // 86400 seconds in a day.
|
to_string((share->maxDays * 86400) / 6) + // 86400 seconds in a day.
|
||||||
" stream.m3u8";
|
" stream.m3u8";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user