Public Member Functions | |
void | format (const string_type &format_str) |
sets the format string: what should be before, and what after the original message, separated by "|" | |
void | format (const string_type &format_before_str, const string_type &format_after_str) |
sets the format strings (what should be before, and what after the original message) | |
void | destination (const string_type &destination_str) |
sets the destinations string - where should logged messages be outputted | |
void | write (const string_type &format_str, const string_type &destination_str) |
Specifies the formats and destinations in one step. | |
template<class destination> | |
void | replace_destination (const string_type &name, destination d) |
Replaces a destination from the named destination. | |
template<class formatter> | |
void | replace_formatter (const string_type &name, formatter d) |
Replaces a formatter from the named formatter. |
#include <boost/logging/format/named_write.hpp>
Contains a very easy interface for using formatters and destinations:
Setting the formatters and destinations to write to is extremely simple:
// Set the formatters (first param) and destinatins (second step) in one step g_l()->writer().write("%time%($hh:$mm.$ss.$mili) [%idx%] |\n", "cout file(out.txt) debug"); // set the formatter(s) g_l()->writer().format("%time%($hh:$mm.$ss.$mili) [%idx%] |\n"); // set the destination(s) g_l()->writer().destination("cout file(out.txt) debug");
%
fmt%
"%idx%"
- writes the index of the message (formatter::idx)"%time%"
- writes the time (formatter::high_precision_time)"%thread_id%"
- writes the thread id (formatter::thread_id)"%"
, double it, like this: "%%"
"|"
is used to specify the original message. What is before it, is prepended to the message, what is after, is appended to the message"%time%"
is configurable. For instance, "%time%($hh:$mm.$ss.$mili)"
writes time like "21:14.24.674"
Example:
"%time%($hh:$mm.$ss.$mili) [%idx%] |\n"
The output can look like:
21:03.17.243 [1] this is so cool
21:03.17.243 [2] first error
21:03.17.243 [3] hello, world
"cout"
- writes to std::cout (destination::cout)"cerr"
- writes to std::cerr (destination::cerr)"debug"
- writes to the debug window: OutputDebugString in Windows, console on Linux (destination::dbg_window)"file"
- writes to a file (destination::file)"file2"
- writes to a second file (destination::file)"rol_file"
- writes to a rolling file (destination::rolling_file)"rol_file2"
- writes to a second rolling file (destination::rolling_file)"file"
, "file2"
, "rol_file"
and "rol_file2"
are configurable(
filename)
to them to specify the file name. Example: "file(out.txt)"
will write to the out.txt fileExamples:
"file(out.txt) cout"
- will write to a file called out.txt and to cout"cout debug"
- will write to cout and debug window (see above)"cout file(out.txt) file2(dbg.txt)"
- will write to cout, and to 2 files - out.txt and dbg.txt"cout rol_file(r.txt)"
- will write to cout and to a rolling_file called r.txt
At this time, named_write does not support tags. However, it's a high priority on my TODO list, so it'll be here soon!
format_write_ | the underlying format writer |
void boost::logging::writer::named_write< format_write_ >::format | ( | const string_type & | format_str | ) | [inline] |
sets the format string: what should be before, and what after the original message, separated by "|"
Example:
"[%idx%] |\n" - this writes "[%idx%] " before the message, and "\n" after the message
If "|" is not present, the whole message is prepended to the message
void boost::logging::writer::named_write< format_write_ >::replace_destination | ( | const string_type & | name, | |
destination | d | |||
) | [inline] |
Replaces a destination from the named destination.
You can use this, for instance, when you want to share a destination between multiple named writers.
void boost::logging::writer::named_write< format_write_ >::replace_formatter | ( | const string_type & | name, | |
formatter | d | |||
) | [inline] |