StreamLog 1.0.0
A lightweight C++11 logging library with stream-based API
Loading...
Searching...
No Matches
streamlog.hpp File Reference

A lightweight C++11 logging library with stream-based API and colored output. More...

#include <ctime>
#include <fstream>
#include <iostream>
#include <sstream>

Go to the source code of this file.

Classes

struct  StreamColor
 ANSI color codes for log levels. More...
class  StreamLog
 Main logging class with singleton pattern. More...
class  StreamLog::LogStatement
 RAII wrapper for building and committing log messages. More...

Enumerations

enum  LogLevel {
  TRACE , DEBUG , INFO , WARN ,
  ERROR , FATAL
}
 Log severity levels. More...

Functions

StreamLog::LogStatement log (LogLevel level)
 Global logging function.

Detailed Description

A lightweight C++11 logging library with stream-based API and colored output.

Author
Derrek Landauer
Version
1.0.0

StreamLog provides a simple, header-friendly logging interface with:

  • Stream-based API familiar to C++ developers
  • Six log levels with colored console output
  • Compile-time log level filtering
  • Zero external dependencies (C++11 standard library only)
  • Optional STL container logging (vectors, maps)
  • Thread-safe Meyer's singleton pattern
  • Extensible via inheritance

Log Levels

  • TRACE: Detailed debugging (function calls, variable dumps, memory addresses)
  • DEBUG: Debug information helpful during development
  • INFO: Normal operational messages, high-level execution tracking
  • WARN: Warning conditions that may require attention
  • ERROR: Error conditions requiring immediate attention
  • FATAL: Critical failures causing application termination

Basic Usage

#include <streamlog.hpp>
int main() {
log(INFO) << "Server started on port " << 8080;
log(ERROR) << "Connection failed";
return 0;
}
A lightweight C++11 logging library with stream-based API and colored output.
StreamLog::LogStatement log(LogLevel level)
Global logging function.
@ ERROR
Error conditions.
Definition streamlog.hpp:76
@ INFO
Informational messages.
Definition streamlog.hpp:74

Configuration

Customize output file and console logging:

StreamLog::instance("myapp.log", true); // custom file, enable console
static StreamLog & instance(const std::string &fileName="output.log", bool consoleOutput=false)
Get the singleton logger instance.

Set compile-time log level filtering:

make DEBUG_LEVEL=3 # Only INFO and above

Enumeration Type Documentation

◆ LogLevel

enum LogLevel

Log severity levels.

Lower levels encompass higher levels when filtering is applied.

Enumerator
TRACE 

Detailed debugging information.

DEBUG 

Debug information.

INFO 

Informational messages.

WARN 

Warning conditions.

ERROR 

Error conditions.

FATAL 

Critical failures.

Function Documentation

◆ log()

Global logging function.

Parameters
levelLog severity level
Returns
LogStatement ready for message streaming
log(INFO) << "Server started on port " << 8080;