View on GitHub

LoggerC++

LoggerC++ (LoggerCpp) is a simple, elegant and efficient C++ logger library.

Download this project as a .zip file Download this project as a tar.gz file

The goals of LoggerC++ are:

Limitations:

Thread-safety is only for Log outputs. You shall not dynamically create and destroy Logger objects in multiple threads. Instead, build them all at startup in you main thread, before other thread startup. Then you are allowed to use them all in parallel.

 Suported platforms:

Developements and tests are done under the following OSs :

Dependencies:

Installation

To use this C++ Logger, you need to include the sources files into your project codebase.

License

Copyright (c) 2013 Sébastien Rombauts (sebastien.rombauts@gmail.com)

Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt or copy at http://opensource.org/licenses/MIT)

Getting started

Principles

First sample demonstrates how to create a Logger and print some logs:

int main ()
{
    // Configure the default severity Level of new Channel objects
    Log::Manager::setDefaultLevel(Log::Log::eNotice);

    // Setup the list of Config for the Output objects,
    Log::Config::Vector configList;
    Log::Config::addOutput(configList, "OutputConsole");
    Log::Config::addOutput(configList, "OutputFile");
    Log::Config::setOption(configList, "filename",          "log.txt");
    Log::Config::setOption(configList, "max_size",          "10000");
    // and configure the Log Manager (create the Output objects)
    Log::Manager::configure(configList);

    // Create a Logger object, using a "Main.Example" Channel
    Log::Logger logger("Main.Example");

    // Test outputs of various kind of variables, and some common stream manipulations.
    std::string     str("string");
    unsigned int    ui  = 123;
    double          dbl = -0.023f;
    logger.debug() << "Variables ; '" << str << "', '" << ui << "', '" << dbl << "'";
    logger.debug() << "Hexa = " << std::hex << 0x75af0 << " test";
    logger.debug() << "Deci = " << std::right << std::setfill('0') << std::setw(8) << 76035 << " test";

    // Test outputs of various severity Level
    logger.debug()  << "Debug.";
    logger.info()   << "Info.";
    logger.notice() << "Notice.";
    logger.warning()<< "Warning.";
    logger.error()  << "Error.";
    logger.critic() << "Critic.";

    // Modify the output Level of the underlying Channel, and test various severity Level again
    logger.setLevel(Log::Log::eWarning);
    logger.debug()  << "NO Debug.";     // NO more debug logs
    logger.info()   << "NO Info.";      // NO more info logs
    logger.notice() << "NO Notice.";    // NO more notice logs
    logger.warning()<< "Warning.";
    logger.error()  << "Error.";
    logger.critic() << "Critic.";

    // Reset Level of the "Main.example" channel by its name
    Log::Manager::get("Main.Example")->setLevel(Log::Log::eDebug);

How to contribute

GitHub website

The most efficient way to help and contribute to this wrapper project is to use the tools provided by GitHub:

Contact

You can also email me directly, I will answer any questions and requests.

Coding Style Guidelines

The source code use the CamelCase naming style variant where :