|
StreamLog 1.0.0
A lightweight C++11 logging library with stream-based API
|
Main logging class with singleton pattern. More...
#include <streamlog.hpp>
Classes | |
| class | LogStatement |
| RAII wrapper for building and committing log messages. More... | |
Public Member Functions | |
| LogStatement | getLogStatement (LogLevel level) |
| Create a LogStatement for the given log level. | |
| LogStatement | operator<< (std::ostream &(*manipulator)(std::ostream &)) |
| Stream manipulator support (e.g., std::endl). | |
| virtual | ~StreamLog () |
| Virtual destructor for inheritance support. | |
| StreamLog (const StreamLog &)=delete | |
| No copy constructor. | |
| StreamLog & | operator= (const StreamLog &)=delete |
| No copy assignment. | |
| StreamLog (StreamLog &&)=delete | |
| No move constructor. | |
| StreamLog & | operator= (StreamLog &&)=delete |
| No move assignment. | |
Static Public Member Functions | |
| static StreamLog & | instance (const std::string &fileName="output.log", bool consoleOutput=false) |
| Get the singleton logger instance. | |
Protected Member Functions | |
| StreamLog (const std::string &fileName, bool consoleOutput=false) | |
| Construct logger with file and console settings. | |
| std::string | levelToString (const LogLevel &level) const |
| Convert LogLevel enum to string. | |
| std::string | getColor () const |
| Get ANSI color code for current log level. | |
| virtual std::string | getTimestamp () const |
| Get current timestamp. | |
| virtual std::stringstream | buildLog (const std::string &message) const |
| Build formatted log message with timestamp and level. | |
| void | writeLog (const std::string &message) |
| Write formatted message to file and optionally console. | |
| void | commitLog (const std::string &message) |
| Commit message if it meets threshold. | |
Protected Attributes | |
| LogLevel | m_level |
| Current log level being written. | |
| LogLevel | m_threshold |
| Minimum level to actually write (compile-time). | |
| std::string | m_fileName |
| Path to log file. | |
| bool | m_consoleOutput |
| Whether to also write to stderr. | |
Main logging class with singleton pattern.
StreamLog provides a thread-safe singleton logger that writes to both file and optionally console. Uses RAII pattern via LogStatement to ensure messages are committed when the statement goes out of scope.
Standard Usage (Singleton):
Custom Logger (Inheritance): Derive from StreamLog and override virtual methods for custom behavior. Derived classes are instantiated directly, NOT as singletons.
|
virtual |
Virtual destructor for inheritance support.
|
delete |
No copy constructor.
|
delete |
No move constructor.
|
explicitprotected |
Construct logger with file and console settings.
| fileName | Path to log file |
| consoleOutput | true to also write to stderr |
|
protectedvirtual |
Build formatted log message with timestamp and level.
| message | Raw message content |
|
protected |
Commit message if it meets threshold.
| message | Message to commit |
|
protected |
Get ANSI color code for current log level.
| LogStatement StreamLog::getLogStatement | ( | LogLevel | level | ) |
Create a LogStatement for the given log level.
| level | Log severity level |
|
protectedvirtual |
Get current timestamp.
|
static |
Get the singleton logger instance.
Uses Meyer's singleton pattern (thread-safe in C++11+).
| fileName | Log file path (only used on first call) |
| consoleOutput | Enable console output (only used on first call) |
|
protected |
Convert LogLevel enum to string.
| level | Log level to convert |
| LogStatement StreamLog::operator<< | ( | std::ostream &(* | manipulator )(std::ostream &) | ) |
Stream manipulator support (e.g., std::endl).
| manipulator | Stream manipulator function |
|
protected |
Write formatted message to file and optionally console.
| message | Message to write |
|
protected |
Whether to also write to stderr.
|
protected |
Path to log file.
|
protected |
Current log level being written.
|
protected |
Minimum level to actually write (compile-time).