C++ Boost

Loglite

Reference

Boost Libraries Index


Reference

Macros
logger class
log_element class
level_element class
trace_element class
filename_element class
line_element class
literal_element class
eol_element class
Statically defined elements class

Macro

BOOST_LOG_INIT(format)
  This macro initializes the logger. Any call to BOOST_LOG before the initialization will be discarded.

  format: Describe the log format using element. Each element has a specific behaviour described below.
    type: element_list_t
    example:
boost::logging::element_list_t list;
list.push_back(boost::logging::trace); 
list.push_back(boost::logging::eol);
    


BOOST_LOG_ADD_OUTPUT_STREAM(sink)
  This macro add a sink to the list. Any call to BOOST_LOG when the sink list is empty will be discarded.

  sink: sink to add. It will be associated with the last format added to the logger.
    type: boost::logging::sink
    example:
bl::sink s1(&std::cout, BOOST_LOG_MASK_LEVEL_2);
s1.attach_qualifier(bl::log);
BOOST_LOG_ADD_OUTPUT_STREAM(s1);
    
BOOST_LOG(mask_level, qualifier, trace)
  This macro log the trace. Any call to BOOST_LOG before the initialization will be discarded.

  mask_level: The mask log level. Will be bounded to the level_element.
    type: mask_t
    example:

  qualifier: The qualifier. Will be bounded to the qualifier_element.
    type: mask_t
    example:

  tracet: List of token that can be streamed into a std::stringstream.
    type: std::stringstream
    example:
BOOST_LOG(1, log, "The error code is: " << errno())
    
BOOST_LOG_UNFORMATTED(mask_level, qualifier, trace)
  This macro log an unformatted trace. Equivalent to BOOST_LOG in usage, it will produce a log that will not follow the format described during the call to BOOST_LOG_INIT. Useful for header and footer of particular log format (i.e.: xml).

  mask_level: The mask log level. Will be bounded to the level_element.
    type: mask_t
    example:

  qualifier: The qualifier. Will be bounded to the qualifier_element.
    type: mask_t
    example:

  tracet: List of token that can be streamed into a std::stringstream.
    type: std::stringstream
    example:
BOOST_LOG_UNFORMATTED(1, log, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl);
    

logger class

namespace boost {

  namespace logging {
    
    typedef enum { SINK = 0, FORMAT }                   sink_format_assoc_e;
    typedef std::list<boost::shared_ptr<log_element> >  element_list_t;
    typedef std::list<boost::shared_ptr<std::ostream> > stream_list_t;
    typedef unsigned short                              mask_t;
    typedef std::vector<scope_item *>                   scope_stack_t;
    typedef struct
    {
      mask_t           m_mask;
      const qualifier *m_qualifier;
      std::string      m_trace;
      std::string      m_filename;
      unsigned int     m_line;
      std::string      m_func_name;
      std::string      m_func_sig;
      scope_stack_t    *m_scope;
    } log_param_t;
    typedef std::list<format>                           format_list_t;
    typedef tuple<sink, format>                         sink_format_assoc_t;
    typedef std::list<sink_format_assoc_t>            sink_format_assoc_list_t;
    typedef std::list<qualifier *>                      qualifier_list_t;
    typedef shared_ptr<logger>                          logger_p;

    class logger
    {
    public: 
      logger();
      static void create_instance();
      static logger_p &get_instance();
      void add_format(format f);
      void add_sink(sink s);
      void add_sink(sink s, format f);
      inline mask_t get_global_log_mask() ;
      void trace(mask_t m, 
                 const qualifier &q, 
                 const std::string &s, 
                 const std::string &f = "",
                 unsigned int l = 0);
      void unformatted_trace(mask_t m, 
                             const qualifier &q, 
                             const std::string &s);
      void trace(log_param_t &log_param);      
      void unformatted_trace(log_param_t &log_param);

      void push_scope(scope_item *s);
      void pop_scope();

    private:
      format_list_t            m_format_list;
      sink_format_assoc_list_t m_sink_format_assoc;
      mask_t                  m_global_log_mask;
      scope_stack_t           m_scope_stack;
#if defined(BOOST_HAS_THREADS)
      boost::mutex             m_mutex;
#endif // BOOST_HAS_THREADS
    };  // logger
  }
}
    

log_element class

class log_element
{
public:
  virtual std::string to_string();
  virtual std::string visit(logger &l, const log_param_t &log_param);
};
    

level_element class

class level_element : public log_element
{
public:
  std::string to_string(level_t l);
  std::string visit(logger &l, const log_param_t &log_param);
};
    

trace_element class

class trace_element : public log_element
{
public:
  std::string to_string(const std::string& s);
  std::string visit(logger &l, const log_param_t &log_param);
};
    

filename_element class

class filename_element : public log_element
{
public:
  filename_element() : m_display_format(full_path) {}
  filename_element(display_format_e d) : m_display_format(d) {}
  std::string to_string();
  std::string visit(logger &l, const log_param_t &log_param);
};
    

filename_element class

class date_element : public log_element
{
public:
  date_element()
  date_element(const std::string &format)
  std::string to_string();
};
    

filename_element class

class time_element : public log_element
{
public:
  time_element()
  time_element(const std::string &format)
  std::string to_string();
};
    

line_element class

class line_element : public log_element
{
public:
  std::string to_string();
  std::string visit(logger &l, const log_param_t &log_param);
};
    

literal_element

class literal_element : public log_element
{
public:
  literal_element(const std::string &l);
  std::string to_string();
private:
  std::string m_literal;
};
    

eot_element

class eot_element : public log_element
{
public:
  std::string to_string() { return "\f"; };
};
    

qualifier_element

class qualifier_element : public log_element
{
public:
  qualifier_element(const qualifier &lq);
  std::string to_string();
};
    

function_name_element

class function_name_element : public log_element
{
public:
  std::string to_string(const std::string &n) { return n; }
  std::string visit(format &f, const log_param_t &log_param);
};
    

pretty_function_name_element

class pretty_function_name_element : public log_element
{
public:
  std::string to_string(const std::string &n) { return n; }
  std::string visit(format &f, const log_param_t &log_param);
};
    

scope_element

class scope_element : public log_element
{
public:
  std::string to_string(const std::string &n) { return n; }
  std::string visit(format &f, const log_param_t &log_param);
};
    

eol_element class

    
class eol_element : public log_element
{
public:
  std::string to_string();
};
    

Statically defined elements

    
level_element     level     = level_element();
filename_element  filename  = filename_element();
line_element      line      = line_element();
date_element      date      = date_element();
time_element      time      = time_element();
trace_element     trace     = trace_element();
eol_element       eol       = eol_element();
    

Revised 31 March 2007 

© Copyright Jean-Daniel Michaud 2007

Use, modification and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)