Boost logo

Boost :

From: JD (jean.daniel.michaud_at_[hidden])
Date: 2007-08-23 13:56:35


   Discussion about a logging library started over some time ago. In the
vault my implementation. As for now, I am implementing some of the
requirements from the boost wiki (

Functional Requirements
  3. Eliminate log statements from generated code
      through the definition a macro.
  4. Full lazy evaluation
  5. Sinks
  7. Configurable log message attributes

Design Requirements
  1. Configurable log message attributes
  2. Macro access

   Here is an example of use:

// Code
#include <fstream>
#include <logging.hpp>

using namespace boost::logging;
namespace bl = boost::logging;

void overheat(int d)
   BOOST_LOG(2, bl::log, "overheat called");
   BOOST_LOG(1, bl::warning, "Warning: Tube overheat! Shutdown system
   BOOST_LOG(1, bl::error, "ERROR: tube overheat: " << d << "d C.
Shutdown should follow");

int do_something()
   BOOST_LOG(2, bl::log, "do_something called");
   BOOST_LOG(2, bl::notice, "do_something is performing some fancy
processing (useless log don't you think?)");

   return 7;

int main(int argc, char **argv)
   boost::logging::logger *l = boost::logging::logger::get_instance();

   boost::logging::format display_format(bl::trace >> bl::eol);
   boost::logging::format file_format("[" >> bl::level >> "],"
>> bl::filename >> "("
>> bl::line >> "),"
>> bl::time >> ","
>> bl::trace
>> bl::eol); // log format

   boost::logging::sink file_sink(new std::ofstream("./output.log"), 3);
   l->add_sink(file_sink, file_format);

   boost::logging::sink display_sink(&std::cout, 1);
   l->add_sink(display_sink, display_format);

   BOOST_LOG(1, bl::log, "Application starting");
   BOOST_LOG(1, bl::notice, "Application version 1.0.3 - Copyright(2007)
World Company");

   BOOST_LOG(1, bl::log, "do_something returned: " << do_something());
   return 0;

Standard output:
Application version 1.0.3 - Copyright(2007) World Company
Warning: Tube overheat! Shutdown system immediatly

Content of output.log:
19:44:26.411856,Application starting
19:44:26.451913,do_something called
19:44:26.451913,do_something returned: 7
19:44:26.451913,overheat called
19:44:26.461928,ERROR: tube overheat: 87d C. Shutdown should follow

   I am welcoming any comment if you think it worth it.
   The library can be found in the vault here:
   The google code page is here:
   The checkout the svn repository: svn checkout loglite

   Note that Andrey Semashev is also working on an implementation that
you can find here:



Boost list run by bdawes at, gregod at, cpdaniel at, john at