Add Logger class candidate for log messages
This commit is contained in:
parent
4c7d538a57
commit
9c040304fe
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
#include <opencv2/imgcodecs.hpp>
|
||||
|
||||
#include "VideoProcessor.hpp"
|
||||
#include "Logger.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue