boost::logging::formatter Namespace Reference

Formatter is a manipulator. It allows you to format the message before writing it to the destination(s). More...


Classes

struct  msg_type
 what is the default type of your string, in formatter_base ? See BOOST_LOG_FORMAT_MSG More...
struct  base
 What to use as base class, for your formatter classes. More...
struct  class_
 Use this when implementing your own formatter class. More...
struct  idx_t
 prefixes each message with an index. More...
struct  append_newline_t
 Appends a new line. More...
struct  append_newline_if_needed_t
 Appends a new line, if not already there. More...
struct  high_precision_time_t
 Prefixes the message with a high-precision time (. You pass the format string at construction. More...
struct  named_spacer_t
 Allows you to contain multiple formatters, and specify a spacer between them. You have a spacer string, and within it, you can escape your contained formatters. More...
struct  spacer_t
 Prepends some info, and appends some info to an existing formatter. More...
struct  uses_tag
 Specifies that a formatter class handles a certain tag class. More...
struct  thread_id_t
 Writes the thread_id to the log. More...
struct  time_t
 Prefixes the message with the time. You pass the format string at construction. More...
struct  time_strf_t
 Prefixes the message with the time, by using strftime function. You pass the format string at construction. More...

Namespaces

namespace  convert
 Allows format convertions - In case you're using a formatter that does not match your string type.
namespace  tag
 Classes that process the tags coming with the library.

Typedefs

typedef
boost::logging::manipulator::implement_op_equal 
implement_op_equal
typedef
boost::logging::manipulator::is_generic 
is_generic
typedef idx_t idx
 idx_t with default values. See idx_t
typedef append_newline_t append_newline
 append_newline_t with default values. See append_newline_t
typedef
append_newline_if_needed_t 
append_newline_if_needed
 append_newline_if_needed_t with default values. See append_newline_if_needed_t
typedef
high_precision_time_t 
high_precision_time
 high_precision_time_t with default values. See high_precision_time_t
typedef named_spacer_t named_spacer
 named_spacer_t with default values. See named_spacer_t
typedef thread_id_t thread_id
 thread_id_t with default values. See thread_id_t
typedef time_t time
 time_t with default values. See time_t
typedef time_strf_t time_strf
 time_strf_t with default values. See time_strf_t

Functions

template<class original_formatter>
detail::find_spacer
< original_formatter >
::type 
spacer (const original_formatter &fmt, const char_type *format_str)


Detailed Description

Formatter is a manipulator. It allows you to format the message before writing it to the destination(s).

Examples of formatters are : prepend the time, prepend high-precision time, prepend the index of the message, etc.

See:


Typedef Documentation

typedef append_newline_t boost::logging::formatter::append_newline

append_newline_t with default values. See append_newline_t

Appends a new line.

Parameters:
convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format. For instance, you might use a cached_string class (see optimize namespace).

typedef append_newline_if_needed_t boost::logging::formatter::append_newline_if_needed

append_newline_if_needed_t with default values. See append_newline_if_needed_t

Appends a new line, if not already there.

Parameters:
convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format. For instance, you might use a cached_string class (see optimize namespace).

typedef high_precision_time_t boost::logging::formatter::high_precision_time

high_precision_time_t with default values. See high_precision_time_t

Prefixes the message with a high-precision time (. You pass the format string at construction.

#include <boost/logging/format/formatter/high_precision_time.hpp>

Internally, it uses boost::date_time::microsec_time_clock. So, our precision matches this class.

The format can contain escape sequences: $dd - day, 2 digits $MM - month, 2 digits $yy - year, 2 digits $yyyy - year, 4 digits $hh - hour, 2 digits $mm - minute, 2 digits $ss - second, 2 digits $mili - milliseconds $micro - microseconds (if the high precision clock allows; otherwise, it pads zeros) $nano - nanoseconds (if the high precision clock allows; otherwise, it pads zeros)

Example:

high_precision_time("$mm:$ss:$micro");

Parameters:
convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format. For instance, you might use a cached_string class (see optimize namespace).

typedef idx_t boost::logging::formatter::idx

idx_t with default values. See idx_t

prefixes each message with an index.

Example:

L_ << "my message";
L_ << "my 2nd message";

This will output something similar to:

[1] my message
[2] my 2nd message

Parameters:
convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format. For instance, you might use a cached_string class (see optimize namespace).

typedef boost::logging::manipulator::implement_op_equal boost::logging::formatter::implement_op_equal

See also:
boost::logging::manipulator::implement_op_equal

typedef boost::logging::manipulator::is_generic boost::logging::formatter::is_generic

See also:
boost::logging::manipulator::is_generic

typedef named_spacer_t boost::logging::formatter::named_spacer

named_spacer_t with default values. See named_spacer_t

Allows you to contain multiple formatters, and specify a spacer between them. You have a spacer string, and within it, you can escape your contained formatters.

#include <boost/logging/format/formatter/named_spacer.hpp>

This allows you:

Example:

#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l(), g_log_filter()->is_enabled() ) 

g_l()->writer().add_formatter( formatter::named_spacer("[%index%] %time% (T%thread%) ")
        .add( "index", formatter::idx())
        .add( "thread", formatter::thread_id())
        .add( "time", formatter::time("$mm")) );

Assuming you'd use the above in code

int i = 1;
L_ << "this is so cool " << i++;
L_ << "this is so cool again " << i++;

You could have an output like this:

[1] 53 (T3536) this is so cool 1
[2] 54 (T3536) this is so cool again 2

Bug:
Use_tags.cpp example when on dedicated thread, fails with named_spacer. If using the old code, it works.

typedef thread_id_t boost::logging::formatter::thread_id

thread_id_t with default values. See thread_id_t

Writes the thread_id to the log.

Parameters:
convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format. For instance, you might use a cached_string class (see optimize namespace).

typedef time_t boost::logging::formatter::time

time_t with default values. See time_t

Prefixes the message with the time. You pass the format string at construction.

It's friendlier than write_time_strf (which uses strftime).

The format can contain escape sequences: $dd - day, 2 digits $MM - month, 2 digits $yy - year, 2 digits $yyyy - year, 4 digits $hh - hour, 2 digits $mm - minute, 2 digits $ss - second, 2 digits

Example: time("Today is $dd/$MM/$yyyy");

Note: for a high precision clock, try high_precision_time (uses boost::date_time)

Parameters:
convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format. For instance, you might use a cached_string class (see optimize namespace).

typedef time_strf_t boost::logging::formatter::time_strf

time_strf_t with default values. See time_strf_t

Prefixes the message with the time, by using strftime function. You pass the format string at construction.

Parameters:
msg_type The type that holds your logged message.
convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format. For instance, you might use a cached_string class (see optimize namespace).


Function Documentation

template<class original_formatter>
detail::find_spacer<original_formatter>::type boost::logging::formatter::spacer ( const original_formatter &  fmt,
const char_type *  format_str 
) [inline]

Prepends some info, and appends some info to an existing formatter.

The syntax is simple: construct a spacer by passing the original formatter, and the text to space (prepend and append). Use:

Examples:

// prefix "[" before index, and append "] " after it.
formatter::spacer( formatter::idx(), "[%] ");

// prefix "{T" before thread_id, and append "} " after it
formatter::spacer( formatter::thread_id(), "{T%} ");

When adding a spacer formatter, you'll do something similar to:

g_l()->writer().add_formatter( formatter::spacer( formatter::idx(), "[%] ") );

However, to make this even simpler, I allow an ever easier syntax:

// equivalent to the above
g_l()->writer().add_formatter( formatter::idx(), "[%] " );



Copyright John Torjo © 2007
Have a question/ suggestion/ comment? Send me feedback