Home

Awesome

Elephant logger

elephantlogger-logo

release-version Build Status license

// Your code
#include <elephantlogger/log.h>

int main(int argc, char** argv) {

    elephantlogger::init();

    LOG_WTF("Log WTF");
    LOG_ERROR("Log error");
    LOG_WARNING("Log warning");
    LOG_CONFIG("Log config");
    LOG_INFO("Log info");
    LOG_TRACE("Log trace");
    LOG_DEBUG("Log debug");

    LOG_DEBUG("Integer value: %d", 42);
    LOG_DEBUG("Float value: %f", 31.9);
    LOG_DEBUG("Bool value (true): %d", true);
    LOG_DEBUG("NULL (Using d): %d", NULL);
    LOG_DEBUG("NULL (Using s): %s", NULL);

    LOG_DEBUG("String: %s / Integer: %d / Float: %f / Char: %c", "Hello", 2, 7.1, 'c');

    int counter = 0;
    while(counter < 12) {
        counter++;
        LOG_DEBUG("Log in loop (counter: %d)", counter);
    }

    return 0;
}

Description

Easy to use and flexible C++ logger with support for custom outputs and filters. The goal is to easily filter and show the logs on several outputs.

Work in progress

Features

Getting Started

#include <elephantlogger/log.h>

int main(int argc, char** argc) {
    elephantlogger::init();

    // Your code

    return 0;
}

Example with a file output

#include <string>
#include <elephantlogger/log.h>
#include <elephantlogger/outputs/LogOutput_File.h>

// Initialize the logger with custom outputs and categories.
static void elephant_customInit() {
    static elephantlogger::LogOutput_File filelog("elephant.log");

    elephantlogger::init();
    elephantlogger::addOutput(&filelog, elephantlogger::LogLevel::Debug);
}

int main(int argc, char** argv) {
    elephant_customInit();

    LOG_WARNING("Some warning log");
    LOG_DEBUG("Some debug log");
    LOG_ERROR("Some error log");
    LOG_CONFIG("Some config log");
    LOG_TRACE("Some trace log");
    LOG_INFO("Some information log");

    return 0;
}

Build the examples

Requirements

Build the examples on GNU/Linux with CMake

mkdir build
cd build
cmake -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release ..
make -j2
make run_ex_simple_usage

DCMAKE_BUILD_TYPE options: Debug / Release / RelWithDebInfo / MinSizeRel

Autoformat

The autoformat uses clang-format to apply the rules. You can autoformat the whole code with the following command:

clang-format -i -style=file include/**/*.h

Examples of codes

Several examples are available in the examples directory.

Generate the documentation

Known BUGs

See the github issues-section

Warning: in case of wrong log format (e.g., %s instead of %d), you will get weird errors without nice warning information (segfault in the worst case).

Authors