Add Logger class candidate for log messages

This commit is contained in:
mattmcw 2026-08-03 11:01:55 -04:00
parent 4c7d538a57
commit 9c040304fe
3 changed files with 42 additions and 1 deletions

View File

@ -6,7 +6,7 @@ project(ffmpeg_opencv_example
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

40
include/Logger.hpp Normal file
View File

@ -0,0 +1,40 @@
#pragma once
#include <iostream>
#include <string_view>
#include <format>
#include <source_location>
#include <chrono>
enum class LogLevel {
Info,
Warning,
Error
};
class Logger {
private :
constexpr std::string_view to_string (LogLevel level) {
switch (level) {
case LogLevel::Info: return "INFO";
case LogLevel::Warning: return "WARN";
case LogLevel::Error: return "ERR ";
}
return "UNKNOWN";
}
public :
void message(LogLevel level, std::string_view message,
const std::source_location location = std::source_location::current()) {
auto now = std::chrono::system_clock::now();
std::cout << std::format("[{:%Y-%m-%d %H:%M:%S}] [{}] [{}:{}] -> {}\n",
now,
to_string(level),
location.file_name(),
location.line(),
message);
}
};

View File

@ -10,6 +10,7 @@
#include <opencv2/imgcodecs.hpp>
#include "VideoProcessor.hpp"
#include "Logger.hpp"
namespace {