https://github.com/neko-box-coder/sslogger
Super Simple Logger for call stack and quick debug logging
https://github.com/neko-box-coder/sslogger
c-plus-plus cpp cpp-macros cpp11 cross-platform header-only logger logging logging-library
Last synced: about 1 year ago
JSON representation
Super Simple Logger for call stack and quick debug logging
- Host: GitHub
- URL: https://github.com/neko-box-coder/sslogger
- Owner: Neko-Box-Coder
- License: apache-2.0
- Created: 2022-08-10T21:12:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-03T11:36:04.000Z (about 1 year ago)
- Last Synced: 2025-03-03T12:33:48.121Z (about 1 year ago)
- Topics: c-plus-plus, cpp, cpp-macros, cpp11, cross-platform, header-only, logger, logging, logging-library
- Language: C++
- Homepage:
- Size: 7.69 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ssLogger ๐
A lightweight, flexible C++11 logging library with call stack tracking and multi-threading support.

## โจ Key Features
- ๐๏ธ **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
## ๐ธ Quick Look
### Call Stack Visualization

### Simple Function Logging

### Thread-Safe Logging

### Log Levels

## ๐ Getting Started
### Installation
1. Add ssLogger to your project:
```shell
git submodule add https://github.com/Neko-Box-Coder/ssLogger.git
# OR
git clone https://github.com/Neko-Box-Coder/ssLogger.git
```
2. Choose your integration method:
#### CMake Integration
```cmake
add_subdirectory(path/to/ssLogger)
target_link_libraries(YourTarget PUBLIC ssLogger)
```
#### Header-Only Usage
1. Add `include/ssLogger` to your include paths
2. Include in your entry point (once):
```cpp
#include "ssLogger/ssLogInit.hpp"
#include "ssLogger/ssLog.hpp"
```
3. Define macro options you want before including `ssLog.hpp`. See [Configuration](#configuration) for all options.
> โ ๏ธ **Warning**: Do not use ssLogger before main() as it uses global static variables.
## ๐ป Basic Usage
### Simple Line Logging
```cpp
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();
```
### Function Call Tracking
```cpp
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");
```
### Log Caching And Thread Control
```cpp
//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");
```
## โ๏ธ Configuration
### Key Configuration Options
| 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](#configuration-details) below.
## ๐ Advanced Features
### Benchmarking
```cpp
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);
```
### Content Logging
```cpp
ssLOG_CONTENT( ProcessData(userID, username, password) );
//Content logging with different log levels
ssLOG_CONTENT_WARNING( RiskyOperation() );
```
### Log Flush
Flushes the output buffer to the console or file.
```cpp
ssLOG_FLUSH();
```
### Log Prepending
Prepends additional message to the log
```cpp
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
```
### Precise Function Exit Log
Using `ssLOG_FUNC_ENTRY` and `ssLOG_FUNC_EXIT` will give you the line number of the exit log.
```cpp
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();
}
```
## ๐ Configuration Details
| 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 (โ ๏ธ contains full path) |
| 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 (โ ๏ธ may affect performance) |
| ssLOG_CALL_STACK_ONLY | 0 | Only show function call stack logs, other logs will be ignored |
## ๐ค Credits
Powered by [termcolor](https://github.com/ikalnytskyi/termcolor) ([license](./External/termcolor%20LICENSE))
## ๐ TODOs:
- Add script for running tests in different configurations