Logging utility with plog initialization. More...
#include <plog/Appenders/RollingFileAppender.h>#include <plog/Init.h>#include <plog/Log.h>#include <plog/Record.h>#include <plog/Severity.h>#include <plog/Util.h>#include <ctime>#include <filesystem>#include <iomanip>#include <iostream>#include "constants.hpp"Go to the source code of this file.
Classes | |
| class | CustomFormatter |
| Single-line plog formatter: "[time] [LEVEL] [file:func:line] msg". More... | |
Functions | |
| void | init_logging (const std::string &app_name, plog::Severity severity=plog::debug) |
| Initialize logging to file in logs/ directory. | |
Logging utility with plog initialization.
Provides simple logging initialization to a file in logs/ directory with rotating file appender. Uses a custom single-line formatter that produces records in the form: [YYYY-MM-DD HH:MM:SS.mmm] [LEVEL] [file.cpp:function:line] message
Usage in main(): init_logging("registration"); // Creates logs/registration.log PLOG_INFO << "Application started"; PLOG_DEBUG << "Debug information"; PLOG_ERROR << "An error occurred";
Definition in file logging.hpp.
| #define PLOG_CAPTURE_FILE |
Definition at line 25 of file logging.hpp.
|
inline |
Initialize logging to file in logs/ directory.
Creates logs/ directory if it doesn't exist and initializes plog with a rolling file appender using CustomFormatter. Log file is named <app_name>.log.
| app_name | Base name for log file (without .log extension). Example: "registration" → logs/registration.log |
| severity | Minimum log level to record (default: plog::debug). Levels: plog::verbose, plog::debug, plog::info, plog::warning, plog::error, plog::fatal |
| std::runtime_error | if directory creation or file initialization fails. |
After calling this function, use plog logging macros: PLOG_VERBOSE << "Very detailed message"; PLOG_DEBUG << "Debug info"; PLOG_INFO << "Info message"; PLOG_WARNING << "Warning"; PLOG_ERROR << "Error"; PLOG_FATAL << "Fatal error";
Each log record is written on its own line, formatted by CustomFormatter as: [YYYY-MM-DD HH:MM:SS.mmm] [LEVEL] [FILE:FUNC:LINE] message
Definition at line 118 of file logging.hpp.
References ansi::text::dim, ansi::color::red, and ansi::reset.