Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tune up time/timing/logs in reprostim-videocapture and QR parsing #102

Merged
merged 20 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
047cce5
Add timestamp to the main log, normalize log level and thread info i…
vmdocua Jun 20, 2024
2f9267a
Add iso format timestamps to the .mkv.log header, #99
vmdocua Jun 21, 2024
eeb509e
Specify parse_wQR.py requirements, #96
vmdocua Jun 21, 2024
5c4dd87
Tune up extend parse_wQR.py, added click skeleton, WiP, #96
vmdocua Jun 24, 2024
d71fd2f
Tune up extend parse_wQR.py, added click skeleton, WiP, #96
vmdocua Jun 24, 2024
2490db0
Provide additional video info in parse_wQR.py logs, WiP #96
vmdocua Jun 25, 2024
56ad2a6
Make QR record model more strict with pydantic based class, WiP #96
vmdocua Jun 25, 2024
aa07fda
Extract video time info based on reprostim capture filename format, W…
vmdocua Jun 25, 2024
0782d8c
Parse expected video duration based on captured *.mkv file name, WiP #96
vmdocua Jun 27, 2024
cddb6de
Calculate QR code time based on start time from file name and code po…
vmdocua Jun 27, 2024
6b2b58f
Adjust time format for filenames?? #98
vmdocua Jul 15, 2024
a8a7c7a
Adjust time format for filenames?? #98
vmdocua Jul 15, 2024
8d19d5e
Adjust time format for filenames??, #98
vmdocua Jul 15, 2024
900b99f
Uniform names to end with _start/_end and to have common types like i…
vmdocua Jul 15, 2024
cc8b033
Restore utility behaviour when QR codes json goes to stdout, but othe…
vmdocua Jul 15, 2024
7dc1321
Added JSON record at the end of parsing with summary info like durati…
vmdocua Jul 15, 2024
67b55d3
Make "do_parse" as generator functions, so it can be used to work wit…
vmdocua Jul 15, 2024
5dc7425
Normalize videocapture metadata JSON logs according to this suggesti…
vmdocua Jul 16, 2024
b889e3d
Provide additional information like kind/index in utility JSON output…
vmdocua Jul 16, 2024
36397ab
Provide additional information like type/index in utility JSON output…
vmdocua Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions Capture/capturelib/include/reprostim/CaptureLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
////////////////////////////////////////////////////////////////////////////////
// Macros

#ifndef _LOG_EXPR
#define _LOG_EXPR(expr, level) buildLogPrefix(getLogPattern(), level) << expr
#endif

#ifndef _ERROR
#define _ERROR(expr) std::cerr << expr << std::endl; _SESSION_LOG_ERROR(expr)
#define _ERROR(expr) std::cerr << _LOG_EXPR(expr, LogLevel::ERROR) << std::endl; _SESSION_LOG_ERROR(expr)
#endif

#ifndef _INFO
#define _INFO(expr) std::cout << expr << std::endl; _SESSION_LOG_INFO(expr)
#define _INFO(expr) std::cout << _LOG_EXPR(expr, LogLevel::INFO) << std::endl; _SESSION_LOG_INFO(expr)
#endif

#ifndef _INFO_RAW
#define _INFO_RAW(expr) std::cout << expr; _SESSION_LOG_INFO(expr)
#endif

#ifndef _VERBOSE
#define _VERBOSE(expr) if( isVerbose() ) { std::cout << expr << std::endl; _SESSION_LOG_DEBUG(expr); }
#define _VERBOSE(expr) if( isVerbose() ) { std::cout << _LOG_EXPR(expr, LogLevel::DEBUG) << std::endl; _SESSION_LOG_DEBUG(expr); }
#endif

// Session logger related macros
Expand Down Expand Up @@ -83,12 +87,18 @@ namespace reprostim {
ERROR = 4
};

enum LogPattern:int {
SIMPLE = 0, // just simple log line
FULL = 1 // detailed log line with timestamp, thread info, log level etc
};

////////////////////////////////////////////////////////////////////////////////
// Functions

LogLevel parseLogLevel(const std::string &level);
void registerFileLogger(const std::string &name, const std::string &filePath, int level = LogLevel::DEBUG);
void unregisterFileLogger(const std::string &name);
std::string buildLogPrefix(LogPattern pattern, LogLevel level);
LogLevel parseLogLevel(const std::string &level);
void registerFileLogger(const std::string &name, const std::string &filePath, int level = LogLevel::DEBUG);
void unregisterFileLogger(const std::string &name);

////////////////////////////////////////////////////////////////////////////////
// Classes
Expand Down Expand Up @@ -173,18 +183,27 @@ namespace reprostim {
//////////////////////////////////////////////////////////////////////////
// Global variables

extern volatile int g_verbose;
extern volatile LogPattern g_logPattern;
extern volatile int g_verbose;

// global TLS variable to hold local session logger
extern thread_local SessionLogger_ptr tl_pSessionLogger;

//////////////////////////////////////////////////////////////////////////
// Inline functions

inline LogPattern getLogPattern() {
return g_logPattern;
}

inline bool isVerbose() {
return g_verbose>0;
}

inline void setLogPattern(LogPattern pattern) {
g_logPattern = pattern;
}

inline void setVerbose(bool verbose) {
g_verbose = verbose ? 1 : 0;
}
Expand Down
1 change: 1 addition & 0 deletions Capture/capturelib/src/CaptureApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace reprostim {
}
pRepromonQueue = nullptr;
unregisterFileLogger(_FILE_LOGGER_NAME);
setLogPattern(LogPattern::SIMPLE);
}

std::string CaptureApp::createOutPath(const std::optional<Timestamp> &ts, bool fCreateDir) {
Expand Down
46 changes: 46 additions & 0 deletions Capture/capturelib/src/CaptureLog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

#include <iostream>
#include <filesystem>

// make log level to be upper case, can be also placed under include/spdlog/tweakme.h
#define SPDLOG_LEVEL_NAMES { "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "CRITICAL", "OFF" };

#include <spdlog/spdlog.h>
#include <spdlog/sinks/basic_file_sink.h>
#include "reprostim/CaptureLib.h"
Expand All @@ -9,10 +13,52 @@ namespace fs = std::filesystem;

namespace reprostim {

volatile LogPattern g_logPattern = LogPattern::SIMPLE; // set default log pattern
volatile int g_verbose = 0;
thread_local SessionLogger_ptr tl_pSessionLogger = nullptr;
std::shared_ptr<spdlog::logger> g_pGlobalLogger = nullptr;

std::string buildLogPrefix(LogPattern pattern, LogLevel level) {
if( pattern != LogPattern::FULL ) {
return "";
}

std::stringstream ss;
const Timestamp &ts = CURRENT_TIMESTAMP();

ss << getTimeFormatStr(ts, "%Y-%m-%d %H:%M:%S");

// put also ms precision
auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(ts.time_since_epoch()) % 1000;
ss << '.' << std::setw(3) << std::setfill('0') << nowMs.count();

// add log level
switch( level ) {
case LogLevel::DEBUG:
ss << " [DEBUG]";
break;
case LogLevel::INFO:
ss << " [INFO]";
break;
case LogLevel::WARN:
ss << " [WARN]";
break;
case LogLevel::ERROR:
ss << " [ERROR]";
break;
default:
ss << " [UNKNOWN]";
break;
}

// add thread id
//std::thread::id thread_id = std::this_thread::get_id();
ss << " [" << spdlog::details::os::thread_id() << "]";

ss << " ";
return ss.str();
}

LogLevel parseLogLevel(const std::string &level) {
if( level == "DEBUG" ) {
return LogLevel::DEBUG;
Expand Down
1 change: 1 addition & 0 deletions Capture/screencapture/src/ScreenCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ int ScreenCaptureApp::parseOpts(AppOpts& opts, int argc, char* argv[]) {
return 1;
case 'f':
registerFileLogger(_FILE_LOGGER_NAME, optarg);
setLogPattern(LogPattern::FULL);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Capture/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.0.230
1.10.0.254
22 changes: 17 additions & 5 deletions Capture/videocapture/src/VideoCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ void FfmpegThread ::run() {

// terminate session logs
_VERBOSE("FfmpegThread leave [" << tid << "]: " << getParams().cmd);
Timestamp ts = CURRENT_TIMESTAMP();
json jm = {
{"type", "session_end"},
{"ts", getTimeStr()},
{"ts", getTimeStr(ts)},
{"ts_iso", getTimeIsoStr(ts)},
{"message", "ffmpeg thread terminated"},
{"start_ts", getParams().start_ts}
{"start_ts", getParams().start_ts},
{"start_ts_iso", getTimeIsoStr(getParams().tsStart)}
};
_METADATA_LOG(jm);
_SESSION_LOG_END_CLOSE_RENAME(outVideoFile2 + ".log");
Expand Down Expand Up @@ -181,12 +184,16 @@ void VideoCaptureApp::onCaptureStop(const std::string& message) {
Timestamp tsStop = CURRENT_TIMESTAMP();
std::string stop_ts = getTimeStr(tsStop);

Timestamp ts = CURRENT_TIMESTAMP();
json jm = {
{"type", "capture_stop"},
{"ts", getTimeStr()},
{"ts", getTimeStr(ts)},
{"ts_iso", getTimeIsoStr(ts)},
{"message", message},
{"start_ts", start_ts},
{"stop_ts", stop_ts}
{"start_ts_iso", getTimeIsoStr(tsStart)},
{"stop_ts", stop_ts},
{"stop_ts_iso", getTimeIsoStr(tsStop)}
};
_METADATA_LOG(jm);

Expand Down Expand Up @@ -273,6 +280,7 @@ int VideoCaptureApp::parseOpts(AppOpts& opts, int argc, char* argv[]) {
return 1;
case 'f':
registerFileLogger(_FILE_LOGGER_NAME, optarg);
setLogPattern(LogPattern::FULL);
break;
}
}
Expand Down Expand Up @@ -331,15 +339,18 @@ void VideoCaptureApp::startRecording(int cx, int cy, const std::string& frameRat

SessionLogger_ptr pLogger = createSessionLogger("session_logger_" + start_ts, outVideoFile + ".log");
_SESSION_LOG_BEGIN(pLogger);
Timestamp ts = CURRENT_TIMESTAMP();
json jm = {
{"type", "session_begin"},
{"ts", getTimeStr()},
{"ts", getTimeStr(ts)},
{"ts_iso", getTimeIsoStr(ts)},
{"version", CAPTURE_VERSION_STRING},
{"appName", appName},
{"serial", targetVideoDev.serial},
{"vDev", targetVideoDev.name},
{"aDev", targetAudioInDev.alsaDeviceName},
{"start_ts", start_ts},
{"start_ts_iso", getTimeIsoStr(tsStart)},
{"cx", cx},
{"cy", cy},
{"frameRate", frameRate}
Expand All @@ -366,6 +377,7 @@ void VideoCaptureApp::startRecording(int cx, int cy, const std::string& frameRat
outPath,
outVideoFile,
start_ts,
tsStart,
pLogger,
fRepromonEnabled,
pRepromonQueue.get() // NOTE: unsafe ownership
Expand Down
1 change: 1 addition & 0 deletions Capture/videocapture/src/VideoCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct FfmpegParams {
const std::string outPath;
const std::string outVideoFile;
const std::string start_ts;
const Timestamp tsStart;
const SessionLogger_ptr pLogger;
const bool fRepromonEnabled;
RepromonQueue* pRepromonQueue;
Expand Down
Loading
Loading