8000 GitHub - Neko-Box-Coder/ssLogger: Super Simple Logger for call stack and quick debug logging
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Neko-Box-Coder/ssLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

demo

Simple Function Logging

demo2

Thread-Safe Logging

demo3

Log Levels

logLevel

πŸš€ Getting Started

Installation

  1. 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
  2. Choose your integration method:

    CMake Integration

    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):
    #include "ssLogger/ssLogInit.hpp"
    #include "ssLogger/ssLog.hpp"
    1. Define macro options you want before including ssLog.hpp.

    πŸ“ For a complete list of options, see Compile Time Configurations below.

⚠️ Warning: Do not use ssLogger before main() as it uses global static variables.

πŸ’» Usage

Simple Line Logging

ssLOG_LINE("Hello, World!");
ssLOG_LINE("Value: " << 42);

//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

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

Caching is useful for situations where a lot of logs are being output in multiple threads.

This allows better performance by avoiding having multiple threads waiting for synchronization to output to file/console but instead save to local thread cache.

Cache can all be output either in chronological order or grouped by thread at a later time.

//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");

Log File Control

By default, when ssLOG_MODE is set to ssLOG_MODE_FILE or ssLOG_MODE_CONSOLE_AND_FILE, the output log file is <Weekday> <Month> <Day> <Hour>_<Minutes>_<Seconds> <Year>_log.txt

ssLOG_ENABLE_LOG_TO_FILE(false)                     //Turns off logging to file at runtime
bool loggingToFile = ssLOG_IS_LOG_TO_FILE_ENABLED();

ssLOG_SET_LOG_FILENAME("custom_log_file.txt")       //Sets output log file at runtime
std::string logfile = ssLOG_GET_LOG_FILENAME();

πŸ” Advanced Features

Benchmarking

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

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.

ssLOG_FLUSH();

Log Prepending

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

Precise Function Exit Log

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();
}

These options can be configured either as CMake options or simply as defines before including ssLogger header.

For exact definitions, checkout ssLogSwitches.hpp

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
ssLOG_DISABLE_LOGS 0 Disable all logging operations

🀝 Credits

Powered by termcolor (license)

πŸ”œ TODOs:

  • Add script for running tests in different configurations

About

Super Simple Logger for call stack and quick debug logging

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0