CPPxDIC
C++ Digital Image Correlation library for fingertip 3D reconstruction
Loading...
Searching...
No Matches
logging.h File Reference

Lightweight, dependency-free logging facility for CPPxDIC. More...

#include <fstream>
#include <mutex>
#include <ostream>
#include <sstream>
#include <string>

Go to the source code of this file.

Classes

class  cppxdic::log::Logger
 Process-wide singleton logger. More...
 
struct  cppxdic::log::Options
 Aggregated options resolved from env/config/CLI, applied in one call. More...
 
class  cppxdic::log::Stream
 RAII stream builder; flushes accumulated text to the logger when it is destroyed at the end of the full expression. More...
 
class  cppxdic::log::Voidify
 Helper that turns the conditional logging expression into a void statement (glog idiom). More...
 

Namespaces

namespace  cppxdic
 DataSerializer - Abstract base class for format-agnostic DIC data I/O.
 
namespace  cppxdic::log
 

Macros

#define LOG_AT(lvl)
 
#define LOG_TRACE   LOG_AT(::cppxdic::log::Level::Trace)
 
#define LOG_DEBUG   LOG_AT(::cppxdic::log::Level::Debug)
 
#define LOG_INFO   LOG_AT(::cppxdic::log::Level::Info)
 
#define LOG_WARN   LOG_AT(::cppxdic::log::Level::Warn)
 
#define LOG_ERROR   LOG_AT(::cppxdic::log::Level::Error)
 

Enumerations

enum class  cppxdic::log::Level {
  cppxdic::log::Trace = 0 , cppxdic::log::Debug = 1 , cppxdic::log::Info = 2 , cppxdic::log::Warn = 3 ,
  cppxdic::log::Error = 4 , cppxdic::log::Off = 5
}
 Severity levels, ordered from most to least verbose. More...
 

Functions

Level cppxdic::log::levelFromString (const std::string &s, Level fallback=Level::Info)
 Parse a level name (case-insensitive): trace, debug, info, warn|warning, error, off.
 
const char * cppxdic::log::levelName (Level l)
 Short, fixed-width display name for a level (e.g. "INFO ").
 
void cppxdic::log::configureFromOptions (const Options &opts)
 Apply env vars, then the supplied options (CLI/config), to the singleton.
 
void cppxdic::log::setLevel (Level l)
 Convenience accessors.
 
bool cppxdic::log::setFile (const std::string &path)
 
bool cppxdic::log::enabled (Level l)
 

Detailed Description

Lightweight, dependency-free logging facility for CPPxDIC.

Replaces the project's ad-hoc std::cout/std::cerr/printf usage with a single leveled logger. Design goals:

  • Five severity levels (Trace, Debug, Info, Warn, Error) plus Off.
  • Independent console and log-file thresholds, so a run can stay quiet on screen while a log file captures full Debug detail.
  • Thread-safe emission (internal mutex), safe under OpenMP.
  • Stream-style macros (LOG_INFO << ...) that short-circuit message construction when the level is disabled (cheap in hot loops).

Verbosity vs. debug:

  • "Verbosity" is the console threshold: ERROR (quietest) -> TRACE (loudest). -q/–quiet raises it; -V/–verbose lowers it; –log-level sets it exactly.
  • "Debug" (–debug or config debug_mode=true) lowers the console threshold to Debug and turns on verbose formatting (timestamp + source location).

Configuration precedence (low -> high), applied by configureFromOptions():

  1. Compiled default (Info to console, Debug to file).
  2. Environment: CPPXDIC_LOG_LEVEL, CPPXDIC_LOG_FILE, CPPXDIC_LOG_CONSOLE.
  3. Config file values (log_level, log_file, debug_mode).
  4. Command-line flags (-V/-q/–log-level/–log-file/–debug).

Definition in file logging.h.

Macro Definition Documentation

◆ LOG_AT

#define LOG_AT (   lvl)
Value:
? (void)0 \
: ::cppxdic::log::Voidify() & ::cppxdic::log::Stream((lvl), __FILE__, __LINE__)
bool enabled(Level l)
Definition logging.h:115
DataSerializer - Abstract base class for format-agnostic DIC data I/O.

Definition at line 163 of file logging.h.

◆ LOG_DEBUG

#define LOG_DEBUG   LOG_AT(::cppxdic::log::Level::Debug)

Definition at line 169 of file logging.h.

◆ LOG_ERROR

#define LOG_ERROR   LOG_AT(::cppxdic::log::Level::Error)

Definition at line 172 of file logging.h.

◆ LOG_INFO

#define LOG_INFO   LOG_AT(::cppxdic::log::Level::Info)

Definition at line 170 of file logging.h.

◆ LOG_TRACE

#define LOG_TRACE   LOG_AT(::cppxdic::log::Level::Trace)

Definition at line 168 of file logging.h.

◆ LOG_WARN

#define LOG_WARN   LOG_AT(::cppxdic::log::Level::Warn)

Definition at line 171 of file logging.h.