CppNCorr
C++ ncorr Digital Image Correlation engine
Loading...
Searching...
No Matches
log.h File Reference

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

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

Go to the source code of this file.

Classes

class  ncorr::log::Logger
 Process-wide singleton logger. More...
 
class  ncorr::log::Stream
 RAII stream builder; flushes its accumulated text to the logger when it is destroyed at the end of the full expression. More...
 
class  ncorr::log::Voidify
 Helper that turns the conditional logging expression back into a void statement (glog idiom). More...
 

Namespaces

namespace  ncorr
 
namespace  ncorr::log
 

Macros

#define NLOG_AT(lvl)
 
#define NLOG_TRACE   NLOG_AT(::ncorr::log::Level::Trace)
 
#define NLOG_DEBUG   NLOG_AT(::ncorr::log::Level::Debug)
 
#define NLOG_INFO   NLOG_AT(::ncorr::log::Level::Info)
 
#define NLOG_WARN   NLOG_AT(::ncorr::log::Level::Warn)
 
#define NLOG_ERROR   NLOG_AT(::ncorr::log::Level::Error)
 

Enumerations

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

Functions

Level ncorr::log::level_from_string (const std::string &s, Level fallback=Level::Info)
 Parse a level name (case-insensitive): trace, debug, info, warn|warning, error, off.
 
const char * ncorr::log::level_name (Level l)
 Short, fixed-width display name for a level (e.g. "INFO ").
 
void ncorr::log::set_level (Level l)
 Set the console threshold (convenience wrapper).
 
void ncorr::log::set_debug (bool on)
 Lower the console threshold to Debug when on is true (used to honour the engine's existing debug flag).
 
bool ncorr::log::set_file (const std::string &path)
 Convenience: open a log file sink (full Debug detail).
 
bool ncorr::log::enabled (Level l)
 True if a message at l would be emitted by any sink.
 

Detailed Description

Lightweight, dependency-free logging facility for CppNCorr.

CppNCorr is a static library consumed by other projects (e.g. CPPxDIC), so the logger is intentionally tiny and brings in no third-party dependency. It provides:

  • Five severity levels (Trace, Debug, Info, Warn, Error) plus Off.
  • Independent thresholds for the console and an optional log file, so a file sink can capture full Debug detail while the console stays quiet.
  • Thread-safe emission (an internal mutex), safe to call from OpenMP parallel regions used by the DIC engine.
  • Stream-style macros (NLOG_INFO << ...) that short-circuit message construction when the level is disabled — important for the per-frame / per-iteration hot loops in ncorr.cpp.

Because the library has no command line of its own, configuration is driven by environment variables (applied lazily on first use) and by the engine's existing debug flag:

  • NCORR_LOG_LEVEL trace|debug|info|warn|error|off (console threshold)
  • NCORR_LOG_FILE path to a log file (full Debug detail is written)
  • NCORR_LOG_CONSOLE 0|1|true|false (disable/enable console output)

A parent application can also configure the logger programmatically via the helpers below before invoking the engine.

Definition in file log.h.

Macro Definition Documentation

◆ NLOG_AT

#define NLOG_AT (   lvl)
Value:
? (void)0 \
: ::ncorr::log::Voidify() & ::ncorr::log::Stream((lvl), __FILE__, __LINE__)
bool enabled(Level l)
True if a message at l would be emitted by any sink.
Definition log.h:107

Definition at line 155 of file log.h.

◆ NLOG_DEBUG

#define NLOG_DEBUG   NLOG_AT(::ncorr::log::Level::Debug)

Definition at line 161 of file log.h.

◆ NLOG_ERROR

#define NLOG_ERROR   NLOG_AT(::ncorr::log::Level::Error)

Definition at line 164 of file log.h.

◆ NLOG_INFO

#define NLOG_INFO   NLOG_AT(::ncorr::log::Level::Info)

Definition at line 162 of file log.h.

◆ NLOG_TRACE

#define NLOG_TRACE   NLOG_AT(::ncorr::log::Level::Trace)

Definition at line 160 of file log.h.

◆ NLOG_WARN

#define NLOG_WARN   NLOG_AT(::ncorr::log::Level::Warn)

Definition at line 163 of file log.h.