NanoLog Documentation

repository·master·Indexed 25 days ago

https://github.com/platformlab/nanolog

A high-performance, nanosecond-scale logging system for C++ that achieves massive throughput by extracting static log metadata at compile-time and deferring formatting to an offline decompression phase. It offers two versions: a C++17 library and a Preprocessor version for maximum performance. Features include a printf-like API with log levels (DEBUG, NOTICE, WARNING, ERROR), asynchronous logging, and a dedicated decompressor tool to convert binary logs into human-readable ASCII.

Tokens
1.6K
Snippets
4
Records
16
Agent score
83%

What's inside NanoLog

  1. Decompress binary logs to human-readable format

    master

    NanoLog produces binary log files to maintain high performance. To read them, you must use the decompressor application produced during the build process.

    Run the following command: ./decompressor decompress <path_to_binary_log>

    ./decompressor decompress ./compressedLog
  2. Prerequisites for NanoLog

    master

    NanoLog is designed for Linux-based systems and requires:

    • C++17 Compiler: GNU g++ 7.5.0 or newer
    • GNU Make: 4.0 or greater
    • Python: 3.4.2 or greater
    • System Libraries: POSIX AIO and Threads (standard on most Linux distributions)
  3. Measure decompression performance across threads with run_sortedDecompressionThreads.sh

    master
    Use run_sortedDecompressionThreads.sh to study the impact of runtime logging concurrency on post-execution decompression. The script varies the number of runtime logging threads producing messages and measures the subsequent decompression time.
  4. Install and use Preprocessor NanoLog

    master

    The Preprocessor version is for advanced users seeking maximum performance. It requires integrating a Python script into your build chain and produces a non-portable library specific to each compilation.

    1. Configure your GNUmakefile:
      • Include NanoLogMakeFrag.
      • Declare USR_SRCS (source files) and USR_OBJS (object files).
      • Use the run-cxx macro instead of g++ to compile all .cc files into .o files.
    2. Build: Running make will invoke a Python script to generate library code specific to your application.
    3. Decompress logs: The decompressor will be generated in your application directory.
  5. Measure log processing speed with run_aggregation.sh

    master
    Use run_aggregation.sh to compare the processing performance of different tools. This script creates a NanoLog log file containing two different log statements in varying ratios and measures the time taken by Python, Awk, C++, and NanoLog to process them.
  6. Run NanoLog benchmarks using provided scripts

    master
    NanoLog benchmarks should not be run by executing the compiled binaries directly. Instead, use the provided shell scripts in the benchmarks/ directory. These scripts handle machine profiling, execution, and result storage in the results/ directory (organized by timestamp).
  7. Run the core NanoLog benchmark with run_bench.sh

    master
    The run_bench.sh script is the primary entry point for benchmarking. It profiles the host machine, runs the core benchmark application, and saves results to a timestamped subdirectory within results/. You can provide an optional suffix when invoking the script to identify your run.
  8. Install and use C++17 NanoLog

    master

    The C++17 version is the easiest to use and works like a traditional library.

    1. Build the library: Navigate to the runtime directory and run make. This produces libNanoLog.a and a decompressor executable.
    2. Integrate into your application:
      • Include the header: #include "NanoLogCpp17.h".
      • Link against NanoLog, pthreads, and POSIX AIO using the flags: -L ./runtime/ -lNanoLog -lrt -pthread.
      • Important: Enable format checking in your compiler (e.g., -Werror=format) to prevent silent log corruption.
    3. Decompress logs: After running your app, use the generated decompressor to turn the binary log into human-readable ASCII.
  9. Use the NANO_LOG API

    master

    NanoLog uses a printf-like API. You must include the appropriate header based on the version you chose (either NanoLogCpp17.h or NanoLog.h) and specify a log level.

    Log Levels:

    • DEBUG
    • NOTICE
    • WARNING
    • ERROR

    You can control the active logging level using NanoLog::setLogLevel(...).

    #include "NanoLogCpp17.h"
    using namespace NanoLog::LogLevels;
    
    int main() 
    {
      NANO_LOG(NOTICE, "Hello World! This is an integer %d and a double %lf\r\n", 1, 2.0);
      return 0;
    }
  10. Log messages using NANO_LOG

    master

    Use the NANO_LOG macro to record messages. It supports standard printf specifiers (except %n), including width and length specifiers.

    To avoid prefixing every call with the NanoLog:: namespace, you can use using namespace NanoLog::LogLevels; to bring DEBUG, NOTICE, WARNING, and ERROR into the current scope.

  11. Configure NanoLog output and log levels

    master

    You can control where NanoLog writes its compressed logs and the minimum severity level required for a message to be persisted.

    • Use NanoLog::setLogFile(path) to specify the output file location. The default is ./compressedLog.
    • Use NanoLog::setLogLevel(level) to set the minimum LogLevel. Valid levels (from least to greatest) are DEBUG, NOTICE, WARNING, and ERROR.