A lightweight, flexible C++11 logging library with call stack tracking and multi-threading support.
- ποΈ Call Stack Tracking: Full function call stack visualization
- π― Multiple Log Levels: FATAL, ERROR, WARNING, INFO, DEBUG with runtime control
- π§΅ Thread Safety: Built-in support for multi-threaded applications
- π Minimal Dependencies: Header-only or CMake integration
- β‘ High Performance: Optional caching and configurable thread safety
- π οΈ Highly Configurable: Extensive compile-time and runtime options
-
Add ssLogger to your project:
git submodule add https://github.com/Neko-Box-Coder/ssLogger.git # OR git clone https://github.com/Neko-Box-Coder/ssLogger.git
-
Choose your integration method:
add_subdirectory(path/to/ssLogger) target_link_libraries(YourTarget PUBLIC ssLogger)
- Add
include/ssLogger
to your include paths - Include in your entry point (once):
#include "ssLogger/ssLogInit.hpp" #include "ssLogger/ssLog.hpp"
- Define macro options you want before including
ssLog.hpp
. See Configuration for all options.
- Add
β οΈ Warning: Do not use ssLogger before main() as it uses global static variables.
ssLOG_LINE("Hello, World!"); //Basic logging
ssLOG_LINE("Value: " << 42); //Stream-style logging
//Different log levels
ssLOG_FATAL("Critical error!");
ssLOG_ERROR("Error occurred");
ssLOG_WARNING("Warning message");
ssLOG_INFO("Information");
ssLOG_DEBUG("Debug info");
//Set runtime log level for current thread
ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_ERROR);
//Get current thread's target log level
int level = ssLOG_GET_CURRENT_THREAD_TARGET_LEVEL();
void ProcessData()
{
ssLOG_FUNC(); //Automatically logs function entry/exit
ssLOG_LINE("Processing...");
}
//Custom function name (great for lambdas)
auto handler = []()
{
ssLOG_FUNC("CustomHandler");
//... code ...
};
//Function tracking with different log levels
ssLOG_FUNC_ERROR("Critical operation");
ssLOG_FUNC_WARNING("Important operation");
ssLOG_FUNC_INFO("Normal operation");
//Cache in current scope
ssLOG_CACHE_OUTPUT_IN_SCOPE();
//Global cache control
ssLOG_ENABLE_CACHE_OUTPUT(); //Enable for all threads
ssLOG_DISABLE_CACHE_OUTPUT(); //Disable for all threads
//Thread-specific cache control
ssLOG_ENABLE_CACHE_OUTPUT_FOR_CURRENT_THREAD(); //Enable for current thread
ssLOG_DISABLE_CACHE_OUTPUT_FOR_CURRENT_THREAD(); //Disable for current thread
bool isCaching = ssLOG_IS_CACHE_OUTPUT_FOR_CURRENT_THREAD(); //Check if current thread is caching
//New thread cache control
ssLOG_ENABLE_CACHE_OUTPUT_FOR_NEW_THREADS(); //Enable for new threads
ssLOG_DISABLE_CACHE_OUTPUT_FOR_NEW_THREADS(); //Disable for new threads
//Reset all thread information
ssLOG_RESET_ALL_THREAD_INFO(); //Clear all thread info and reset thread ID counter
//Output cached logs
ssLOG_OUTPUT_ALL_CACHE(); //Output all cached logs
ssLOG_OUTPUT_ALL_CACHE_GROUPED(); //Output grouped by thread
//Combine caching with log levels
ssLOG_CACHE_OUTPUT_IN_SCOPE();
ssLOG_ERROR("This error will be cached");
ssLOG_WARNING("This warning will be cached");
Option | Default | Description |
---|---|---|
ssLOG_CALL_STACK | 1 | Enable function call stack tracking |
ssLOG_THREAD_SAFE_OUTPUT | 1 | Enable thread-safe output |
ssLOG_LEVEL | 3 | Compile-time log level (0:NONE to 5:DEBUG) |
ssLOG_MODE | 0 | Log mode for ssLogger (0: CONSOLE, 1: FILE, 2: CONSOLE_AND_FILE) |
ssLOG_SHOW_DATE | 0 | Show date in logs |
ssLOG_SHOW_TIME | 1 | Show time in logs |
π For a complete list of options, see Configuration Details below.
auto benchmark = ssLOG_BENCH_START("Operation");
//... code to benchmark ...
ssLOG_BENCH_END(benchmark);
//Benchmarking with different log levels
auto benchError = ssLOG_BENCH_ERROR("Critical Operation");
//... code ...
ssLOG_BENCH_END(benchError);
ssLOG_CONTENT( ProcessData(userID, username, password) );
//Content logging with different log levels
ssLOG_CONTENT_WARNING( RiskyOperation() );
Flushes the output buffer to the console or file.
ssLOG_FLUSH();
Prepends additional message to the log
ssLOG_PREPEND("My prepend message");
ssLOG_LINE("Test"); //"My prepend message" will be prepended for current thread
ssLOG_PREPEND_RESET();
ssLOG_LINE("Test"); //Normal log message
Using ssLOG_FUNC_ENTRY
and ssLOG_FUNC_EXIT
will give you the line number of the exit log.
void ProcessTransaction(int amount)
{
ssLOG_FUNC_ENTRY();
ssLOG_LINE("Processing amount: " << amount);
if(amount <= 0)
{
ssLOG_ERROR("Invalid amount");
ssLOG_FUNC_EXIT();
return;
}
//...processing...
ssLOG_FUNC_EXIT();
}
Define Macro Name | Default | Description |
---|---|---|
ssLOG_CALL_STACK | 1 | Show call stack for logged functions |
ssLOG_LOG_WITH_ASCII | 0 | Use ASCII-only characters |
ssLOG_SHOW_FILE_NAME | 1 | Show file name ( |
ssLOG_SHOW_LINE_NUM | 1 | Show line numbers |
ssLOG_SHOW_FUNC_NAME | 1 | Show function names |
ssLOG_SHOW_DATE | 0 | Show log date |
ssLOG_SHOW_TIME | 1 | Show log time |
ssLOG_THREAD_SAFE_OUTPUT | 1 | Enable thread-safe output |
ssLOG_SHOW_THREADS | 1 | Show thread IDs |
ssLOG_MODE | 0 | Log mode for ssLogger (0: CONSOLE, 1: FILE, 2: CONSOLE_AND_FILE) |
ssLOG_USE_ESCAPE_SEQUENCES | 0 | Force use of escape sequences |
ssLOG_PREPEND_LOC | 0 | Where to insert preprend (0: BEFORE_FUNC_NAME, 1: BEFORE_FILE_NAME, 2: BEFORE_MESSAGE) |
ssLOG_LEVEL | 3 | Compile-time log level (0:NONE, 1:FATAL, 2:ERROR, 3:WARNING, 4:INFO, 5:DEBUG) |
ssLOG_USE_WINDOWS_COLOR | 0 | Force use of Windows color codes |
ssLOG_THREAD_VSPACE | 4 | Vertical space between individual threads outputs |
ssLOG_IMMEDIATE_FLUSH | 0 | Flush the log output immediately for each log ( |
ssLOG_CALL_STACK_ONLY | 0 | Only show function call stack logs, other logs will be ignored |
Powered by termcolor (license)
- Add script for running tests in different configurations