logging

#include <compatibility/hpx/util/logging.hpp>

#include <compatibility/hpx/util/logging/format_fwd.hpp>

#include <compatibility/hpx/util/logging/format.hpp>

#include <compatibility/hpx/util/logging/logging.hpp>

#include <compatibility/hpx/util/logging/writer/format_write.hpp>

#include <compatibility/hpx/util/logging/writer/named_write.hpp>

#include <compatibility/hpx/util/logging/format/named_write.hpp>

#include <compatibility/hpx/util/logging/format/named_write_fwd.hpp>

#include <compatibility/hpx/util/logging/format/op_equal.hpp>

#include <compatibility/hpx/util/logging/format/optimize.hpp>

#include <compatibility/hpx/util/logging/format/array.hpp>

#include <compatibility/hpx/util/logging/format/formatter/thread_id.hpp>

#include <compatibility/hpx/util/logging/format/formatter/spacer.hpp>

#include <compatibility/hpx/util/logging/format/formatter/time_strf.hpp>

#include <compatibility/hpx/util/logging/format/formatter/time.hpp>

#include <compatibility/hpx/util/logging/format/formatter/high_precision_time.hpp>

#include <compatibility/hpx/util/logging/format/formatter/named_spacer.hpp>

#include <compatibility/hpx/util/logging/format/formatter/convert_format.hpp>

#include <compatibility/hpx/util/logging/format/formatter/defaults.hpp>

#include <compatibility/hpx/util/logging/format/destination/convert_destination.hpp>

#include <compatibility/hpx/util/logging/format/destination/named.hpp>

#include <compatibility/hpx/util/logging/format/destination/file.hpp>

#include <compatibility/hpx/util/logging/format/destination/defaults.hpp>

#include <hpx/logging.hpp>

Defines

LAGAS_(lvl)
LPT_(lvl)
LTIM_(lvl)
LPROGRESS_
LHPX_(lvl, cat)
LAPP_(lvl)
LDEB_
LTM_(lvl)
LRT_(lvl)
LOSH_(lvl)
LERR_(lvl)
LLCO_(lvl)
LPCS_(lvl)
LAS_(lvl)
LBT_(lvl)
LFATAL_
LAGAS_CONSOLE_(lvl)
LPT_CONSOLE_(lvl)
LTIM_CONSOLE_(lvl)
LHPX_CONSOLE_(lvl)
LAPP_CONSOLE_(lvl)
LDEB_CONSOLE_
LAGAS_ENABLED(lvl)
LPT_ENABLED(lvl)
LTIM_ENABLED(lvl)
LHPX_ENABLED(lvl)
LAPP_ENABLED(lvl)
LDEB_ENABLED

Functions

template <typename T>
bootstrap_logging const &operator<<(bootstrap_logging const &l, T&&)

Variables

constexpr bootstrap_logging lbt_
struct bootstrap_logging

Public Functions

constexpr bootstrap_logging()

#include <hpx/logging/format_fwd.hpp>

#include <hpx/logging/format.hpp>

Include this file when you’re using formatters and destinations, and you want to define the logger classes, in a source file (using HPX_DEFINE_LOG)

namespace hpx
namespace util
namespace logging
namespace format_and_write

The format_and_write classes know how to call the formatter and destination objects.

Usually you’ll be happy with the format_and_write::simple class - which simply calls operator() on the formatters , and operator() on the destinations.

Note that usually the formatter and destination class just have an operator(), which when called, formats the message or writes it to a destination. In case your formatters/destinations are more complex than that (for instance, more than a member function needs to be called), you’ll have to implement your own format_and_write class.

struct simple
#include <format.hpp>

Formats the message, and writes it to destinations.

  • calls operator() on the formatters , and operator() on the destinations. Ignores clear_format() commands.

If you derive from

destination::base, this type can be destination::base::raw_param (see below).
Parameters
  • msg_type: The message to pass to the formatter. This is the type that is passed to the formatter objects and to the destination objects. Thus, it needs to be convertible to the argument to be sent to the formatter objects and to the argument to be sent to the destination objects. Usually, it’s the argument you pass on to your destination classes.

Example:

typedef destination::base<const std::string &> dest_base;
// in this case : msg_type = std::string = dest_base::raw_param
struct write_to_cout : dest_base {
    void operator()(param msg) const {
        std::cout << msg ;
    }
};


typedef destination::base<const std::string &> dest_base;
// in this case : msg_type = cache_string = dest_base::raw_param
struct write_to_file : dest_base, ... {
    void operator()(param msg) const {
        context() << msg ;
    }
};

Public Functions

simple(msg_type &msg)
template <class formatter_ptr>
void format(const formatter_ptr &fmt)
template <class destination_ptr>
void write(const destination_ptr &dest)
void clear_format()

Protected Attributes

msg_type &m_msg
namespace msg_route

Specifies the route : how formatting and writing to destinations take place.

Classes in this namespace specify when formatters and destinations are to be called.

See
msg_route::simple

template <class formatter_array, class destination_array>
struct formatter_and_destination_array_holder
#include <format.hpp>

Recomended base class for message routers that need access to the underlying formatter and/or destination array.

Protected Functions

formatter_and_destination_array_holder(const formatter_array &formats_, const destination_array &destinations_)
const formatter_array &formats() const
const destination_array &destinations() const

Private Members

const formatter_array &m_formats
const destination_array &m_destinations
struct simple
#include <format.hpp>

Represents a simple router - first calls all formatters.

  • in the order they were added, then all destinations - in the order they were added

Example:

typedef logger< format_write > logger_type;
HPX_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
HPX_DEFINE_LOG(g_l, logger_type)
#define L_ HPX_LOG_USE_LOG_IF_FILTER(g_l(), g_log_filter()->is_enabled() )

// add formatters : [idx] [time] message [enter]
g_l()->writer().add_formatter( write_idx() );
g_l()->writer().add_formatter( write_time() );
g_l()->writer().add_formatter( append_newline() );

// write to cout and file
g_l()->writer().add_destination( write_to_cout() );
g_l()->writer().add_destination( write_to_file("out.txt") );

// usage
int i = 1;
L_ << "testing " << i << i+1 << i+2;

In the above case:

  • First, the formatters are called: write_idx() is called, then write_time(), then append_newline().
  • Then, the destinations are called: write_to_cout(), and then write_to_file().

Parameters
  • format_base: The base class for all formatter classes from your application. See manipulator.
  • destination_base: The base class for all destination classes from your application. See manipulator.

Public Types

typedef formatter::base::ptr_type formatter_ptr
typedef destination::base::ptr_type destination_ptr
typedef std::vector<formatter_ptr> f_array
typedef std::vector<destination_ptr> d_array

Public Functions

template <class formatter_array, class destination_array>
simple(const formatter_array&, const destination_array&)
void append_formatter(formatter_ptr fmt)
void del_formatter(formatter_ptr fmt)
void append_destination(destination_ptr dest)
void del_destination(destination_ptr dest)
template <class format_and_write>
void write(msg_type &msg) const

Private Members

write_info m_to_write
struct write_info

Public Members

f_array formats
d_array destinations

#include <hpx/logging/logging.hpp>

Include this file when you’re using the logging lib, but don’t necessarily want to use formatters and destinations. If you want to use formatters and destinations, then you can include this one instead:

#include <hpx/logging/format_fwd.hpp>

#include <hpx/logging/writer/format_write.hpp>

#include <hpx/logging/writer/named_write.hpp>

namespace hpx
namespace util
namespace logging
namespace writer
struct named_write
#include <named_write.hpp>

Composed of a named formatter and a named destinations. Thus, you can specify the formatting and destinations as strings.

#include <hpx/logging/format/named_write.hpp>

Contains a very easy interface for using formatters and destinations:

  • at construction, specify 2 params: the formatter string and the destinations string

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");

Public Functions

named_write()
void format(const std::string &format_str)

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 format(const std::string &format_before_str, const std::string &format_after_str)

sets the format strings (what should be before, and what after the original message)

void destination(const std::string &destination_str)

sets the destinations string - where should logged messages be outputted

void write(const std::string &format_str, const std::string &destination_str)

Specifies the formats and destinations in one step.

const std::string &format() const
const std::string &destination() const
void operator()(msg_type &msg) const
template <class destination>
void replace_destination(const std::string &name, destination d)

Replaces a destination from the named destination.

You can use this, for instance, when you want to share a destination between multiple named writers.

template <class formatter>
void replace_formatter(const std::string &name, formatter d)

Replaces a formatter from the named formatter.

You can use this, for instance, when you want to share a formatter between multiple named writers.

template <class formatter>
void add_formatter(formatter fmt)
template <class destination>
void add_destination(const std::string &name, destination d)

Private Functions

template <class manipulator, class parser_type>
void set_and_configure(manipulator &manip, const std::string &name, parser_type parser)
void init()

Private Members

formatter::named_spacer_t<formatter::do_convert_format::prepend> m_format_before
formatter::named_spacer_t<formatter::do_convert_format::append> m_format_after
destination::named m_destination
format_write m_writer
std::string m_format_str
std::string m_format_before_str
std::string m_format_after_str
std::string m_destination_str
struct parse_destination

Public Functions

bool has_manipulator_name() const
std::string get_manipulator_name() const
void clear()
void add(char c)

Private Members

std::string m_manipulator
struct parse_formatter

Public Functions

bool has_manipulator_name() const
std::string get_manipulator_name() const
void clear()
void add(char c)

Private Members

std::string m_manipulator

#include <hpx/logging/format/named_write.hpp>

#include <hpx/logging/format/named_write_fwd.hpp>

#include <hpx/logging/format/op_equal.hpp>

namespace hpx
namespace util
namespace logging
namespace op_equal

Implements operator== for manipulators.

Functions

bool operator==(const same_type_op_equal_top &a, const same_type_op_equal_top &b)
template <class type>
struct same_type_op_equal : public hpx::util::logging::op_equal::same_type_op_equal_base
#include <op_equal.hpp>

Implements operator==, which compares two objects. If they have the same type, it will compare them using the type’s member operator==.

The only constraint is that operator== must be a member function

Public Functions

virtual bool equals(const same_type_op_equal_top &other) const
struct same_type_op_equal_base : public virtual hpx::util::logging::op_equal::same_type_op_equal_top
#include <op_equal.hpp>

Base class when you want to implement operator== that will compare based on type and member operator==.

See
same_type_op_equal

Subclassed by hpx::util::logging::op_equal::same_type_op_equal< type >

struct same_type_op_equal_top

Subclassed by hpx::util::logging::op_equal::same_type_op_equal_base

Public Functions

virtual bool equals(const same_type_op_equal_top&) const = 0

Protected Functions

same_type_op_equal_top()
virtual ~same_type_op_equal_top()
same_type_op_equal_top(const same_type_op_equal_top&)

#include <hpx/logging/format/optimize.hpp>

namespace hpx
namespace util
namespace logging
namespace optimize

Gathering the message: contains optimizers for formatting and/or destinations: for example, caching techniques.

Functions

template <class stream>
stream &operator<<(stream &out, const cache_string_one_str &val)
struct cache_string_one_str
#include <optimize.hpp>

Optimizes the formatting for prepending and/or appending strings to the original message.

It keeps all the modified message in one string. Useful if some formatter needs to access the whole string at once.

reserve_prepend() - the size that is reserved for prepending (similar to string::reserve function) reserve_append() - the size that is reserved for appending (similar to string::reserve function)

Note : as strings are prepended, reserve_prepend() shrinks. Same goes for append.

Public Types

typedef cache_string_one_str self_type

Public Functions

cache_string_one_str(std::size_t reserve_prepend_, std::size_t reserve_append_, std::size_t grow_size_ = 10)

Parameters
  • reserve_prepend: - how many chars to have space to prepend by default
  • reserve_append: - how many chars to have space to append by default
  • grow_size: - in case we add a string and there’s no room for it, with how much should we grow? We’ll grow this much in addition to the added string
    • in the needed direction

cache_string_one_str(const std::string &msg, std::size_t reserve_prepend_ = 10, std::size_t reserve_append_ = 10, std::size_t grow_size_ = 10)

Parameters
  • msg: - the message that is originally cached
  • reserve_prepend: - how many chars to have space to prepend by default
  • reserve_append: - how many chars to have space to append by default
  • grow_size: - in case we add a string and there’s no room for it, with how much should we grow? We’ll grow this much in addition to the added string
    • in the needed direction

cache_string_one_str(cache_string_one_str &&other)
cache_string_one_str()
void set_string(const std::string &str)
std::size_t reserve_prepend() const
std::size_t reserve_append() const
std::size_t grow_size() const
void reserve_prepend(std::size_t new_size)
void reserve_append(std::size_t new_size)
void grow_size(std::size_t new_size)
void prepend_string(const char *str)
void append_string(const char *str)
void prepend_string(const std::string &str)

pre-pends a string (inserts it at the beginning)

void append_string(const std::string &str)

appends a string (inserts it at the end)

template <class stream_type>
void to_stream(stream_type &stream) const

writes the current cached contents to a stream

const std::string &full_string() const

returns the full string

operator const std::string&() const

Private Functions

void resize_string(std::size_t reserve_prepend_, std::size_t reserve_append_)
bool is_string_set() const

Private Members

std::size_t m_reserve_prepend
std::size_t m_reserve_append
std::size_t m_grow_size
std::string m_str
bool m_full_msg_computed
std::string m_full_msg

Private Static Functions

static std::size_t str_len(const char *str)
static std::size_t str_len(const wchar_t *str)

#include <hpx/logging/format/array.hpp>

namespace hpx
namespace util
namespace logging
namespace array
template <class base_type>
class ptr_holder
#include <array.hpp>

Holds an array of manipulators (formatters or destinations). It owns them, holding them internally as smart pointers Each function call is locked.

The base_type must implement operator==

When you call get_ptr() or del(), the type you provide, must implement operator==(const type& , const base_type&)

Public Types

typedef base_type value_type
typedef std::unique_ptr<value_type> ptr_type
typedef std::vector<ptr_type> array_type

Public Functions

template <class derived>
base_type *append(derived val)
template <class derived>
base_type *get_ptr(derived val) const
template <class derived>
void del(derived val)
void del(base_type *p)

Private Members

array_type m_array

#include <hpx/logging/format/formatter/thread_id.hpp>

namespace hpx
namespace util
namespace logging
namespace formatter

Typedefs

typedef thread_id_t 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).

template <class convert = do_convert_format::prepend>
struct thread_id_t : public is_generic
#include <thread_id.hpp>

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).

Public Types

typedef convert convert_type

Public Functions

void operator()(msg_type &msg) const
bool operator==(const thread_id_t&) const

#include <hpx/logging/format/formatter/spacer.hpp>

namespace hpx
namespace util
namespace logging
namespace formatter

Functions

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

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:

  • % to mean the original formatter text
  • anything before "%" is prepended before
  • anything after "%" is appended after

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(), "[%] " );

template <class convert, class original_formatter, bool is_generic_formatter>
struct spacer_t : public original_formatter
#include <spacer.hpp>

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:

  • % to mean the original formatter text
  • anything before "%" is prepended before
  • anything after "%" is appended after

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(), "[%] " );

Public Types

typedef original_formatter::param param
typedef original_formatter spacer_base

Public Functions

spacer_t(const original_formatter &fmt, const char *format_str)
void operator()(param msg) const

Private Functions

void parse_format(const std::string &format_str)

Private Members

std::string m_prefix
std::string m_suffix
template <class convert, class original_formatter>
template<>
struct spacer_t<convert, original_formatter, true> : public original_formatter

Public Types

typedef original_formatter spacer_base

Public Functions

spacer_t(const original_formatter &fmt, const char *format_str)
void operator()(msg_type &msg) const

Private Functions

void parse_format(const std::string &format_str)

Private Members

std::string m_prefix
std::string m_suffix

#include <hpx/logging/format/formatter/time_strf.hpp>

namespace hpx
namespace util
namespace logging
namespace formatter

Typedefs

typedef time_strf_t 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).

template <class convert = do_convert_format::prepend>
struct time_strf_t : public is_generic
#include <time_strf.hpp>

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).

Public Types

typedef convert convert_type

Public Functions

time_strf_t(const std::string &format, bool localtime)

constructs a time_strf object

Parameters
  • format: the time format , strftime-like
  • localtime: if true, use localtime, otherwise global time

void operator()(msg_type &msg) const
bool operator==(const time_strf_t &other) const

Private Members

std::string m_format
bool m_localtime

#include <hpx/logging/format/formatter/time.hpp>

namespace hpx
namespace util
namespace logging
namespace formatter

Typedefs

typedef time_t 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 hpx::util::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).

template <class convert = do_convert_format::prepend>
struct time_t : public is_generic, public non_const_context<hpx::util::logging::detail::time_format_holder>
#include <time.hpp>

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 hpx::util::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).

Public Types

typedef convert convert_type
typedef non_const_context<hpx::util::logging::detail::time_format_holder> non_const_context_base

Public Functions

time_t(const std::string &format)

constructs a time object

void write_time(msg_type &msg, time_t val) const
void operator()(msg_type &msg) const
bool operator==(const time_t &other) const
void configure(const std::string &str)

configure through script

the string = the time format

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

namespace hpx
namespace util
namespace logging
namespace formatter

Typedefs

typedef high_precision_time_t 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 <hpx/logging/format/formatter/high_precision_time.hpp>

Internally, it uses hpx::util::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).

template <class convert = do_convert_format::prepend>
struct high_precision_time_t : public is_generic, public non_const_context<hpx::util::logging::detail::time_format_holder>
#include <high_precision_time.hpp>

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

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

Internally, it uses hpx::util::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).

Public Types

typedef convert convert_type
typedef non_const_context<hpx::util::logging::detail::time_format_holder> non_const_context_base

Public Functions

high_precision_time_t(const std::string &format)

constructs a high_precision_time object

void write_high_precision_time(msg_type &msg, std::chrono::time_point<std::chrono::system_clock> val) const
void operator()(msg_type &msg) const
bool operator==(const high_precision_time_t &other) const
void configure(const std::string &str)

configure through script

the string = the time format

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

namespace hpx
namespace util
namespace logging
namespace formatter
template <class convert>
struct named_spacer_t : public is_generic, public non_const_context<detail::named_spacer_context<convert>>
#include <named_spacer.hpp>

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 <hpx/logging/format/formatter/named_spacer.hpp>

This allows you:

  • to hold multiple formatters
  • each formatter is given a name, when being added
  • you have a spacer string, which contains what is to be prepended or appended to the string (by default, prepended)
  • a formatter is escaped with '%' chars, like this "%name%"
  • if you want to write the '%', just double it, like this: "this %% gets written"

Example:

#define L_ HPX_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

Public Types

typedef non_const_context<detail::named_spacer_context<convert>> context_base

Public Functions

named_spacer_t(const std::string &str = std::string())
named_spacer_t &string(const std::string &str)
template <class formatter>
named_spacer_t &add(const std::string &name, formatter fmt)
void del(const std::string &name)
void configure_inner(const std::string &name, const std::string &configure_str)
void operator()(msg_type &msg) const
bool operator==(const named_spacer_t &other) const

#include <hpx/logging/format/formatter/convert_format.hpp>

namespace hpx
namespace util
namespace logging
namespace formatter
struct do_convert_format
struct append

Public Static Functions

template <class string>
static const std::string &get_underlying_string(const string &str)
template <class string>
static void write(const char *src, string &dest)
template <class src_type, class string>
static void write(const src_type &src, string &dest)
template <class src_type, class string>
static void write(src_type &src, string &dest)
struct prepend

Public Static Functions

template <class string>
static const std::string &get_underlying_string(const string &str)
template <class string>
static void write(const char *src, string &dest)
template <class src_type, class string>
static void write(const src_type &src, string &dest)
template <class src_type, class string>
static void write(src_type &src, string &dest)
namespace convert

Allows format convertions.

  • In case you’re using a formatter that does not match your string type

In case you want to use a formatter developed by someone else (for instance, a formatter provided by this lib), perhaps you’re using another type of string to hold the message

  • thus, you need to provide a conversion function

Example: FIXME

> convert_format::prepend

explain that you can extend the following - since they’re namespaces!!! so that you can “inject” your own write function in the convert_format::prepend/orwhatever namespace, and then it’ll be automatically used!

namespace append

Functions

void write(const std::string &src, std::string &dest)
void write(const std::string &src, hpx::util::logging::optimize::cache_string_one_str &dest)
void write(const char *src, std::string &dest)
void write(const char *src, hpx::util::logging::optimize::cache_string_one_str &dest)
namespace prepend

Example : write_time

Functions

void write(const char *src, std::string &dest)
void write(const std::string &src, std::string &dest)
void write(const std::string &src, hpx::util::logging::optimize::cache_string_one_str &dest)
void write(const char *src, hpx::util::logging::optimize::cache_string_one_str &dest)

#include <hpx/logging/format/formatter/defaults.hpp>

namespace hpx
namespace util
namespace logging
namespace formatter

Typedefs

typedef idx_t 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 append_newline_t 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 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).

template <class convert = do_convert_format::append>
struct append_newline_if_needed_t : public is_generic
#include <defaults.hpp>

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).

Public Types

typedef convert convert_type

Public Functions

void operator()(msg_type &str) const
bool operator==(const append_newline_if_needed_t&) const
template <class convert = do_convert_format::append>
struct append_newline_t : public is_generic
#include <defaults.hpp>

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).

Public Types

typedef convert convert_type

Public Functions

void operator()(msg_type &str) const
bool operator==(const append_newline_t&) const
template <class convert = do_convert_format::prepend>
struct idx_t : public is_generic, public formatter::non_const_context<std::uint64_t>
#include <defaults.hpp>

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).

Public Types

typedef formatter::non_const_context<std::uint64_t> non_const_context_base
typedef convert convert_type

Public Functions

idx_t()
void operator()(msg_type &str) const
bool operator==(const idx_t&) const

#include <hpx/logging/format/destination/convert_destination.hpp>

namespace hpx
namespace util
namespace logging
namespace destination
namespace convert

Allows writing messages to destinations.

It has 2 function overloads:

  • write(message, output) - writes the given message, to the given output
  • do_convert(message, into<other_type>() );

FIXME

Functions

template <class obj>
void write(const obj &m, std::ostream &out)
void write(const char *m, std::ostream &out)
const char *do_convert(const char *c, const into<const char *>&)
const char *do_convert(const std::string &s, const into<const char *>&)
const std::string &do_convert(const std::string &s, const into<std::string>&)

#include <hpx/logging/format/destination/named.hpp>

namespace hpx
namespace util
namespace logging
namespace destination
struct named : public is_generic, public non_const_context<detail::named_context>
#include <named.hpp>

Allows you to contain multiple destinations, give each such destination a name. Then, at run-time, you can specify a format string which will specify which destinations to be called, and on what order.

This allows you:

  • to hold multiple destinations
  • each destination is given a name, when being added. The name must not contain spaces and must not start with ‘+’/’-‘ signs
  • you have a format string, which contains what destinations to be called, and on which order

The format string contains destination names, separated by space.

When a message is written to this destination, I parse the format string. When a name is encountered, if there’s a destination corresponding to this name, I will call it.

Example:

g_l()->writer().add_destination(
    destination::named("cout out debug")
        .add( "cout", destination::cout())
        .add( "debug", destination::dbg_window() )
        .add( "out", destination::file("out.txt"))
     );

In the above code, we’ll write to 3 destinations, in the following order:

  • first, to the console
  • second, to the out.txt file
  • third, to the debug window

Public Types

typedef non_const_context<detail::named_context> non_const_context_base

Public Functions

named(const std::string &format_string = std::string())

constructs the named destination

Parameters
  • named_name: name of the named
  • set: [optional] named settings - see named_settings class, and dealing_with_flags

void operator()(const msg_type &msg) const
named &string(const std::string &str)
template <class destination>
named &add(const std::string &name, destination dest)
void del(const std::string &name)
void configure_inner(const std::string &name, const std::string &configure_str)
bool operator==(const named &other) const

#include <hpx/logging/format/destination/file.hpp>

namespace hpx
namespace util
namespace logging
namespace destination
struct file : public is_generic, public non_const_context<detail::file_info>
#include <file.hpp>

Writes the string to a file.

Public Types

typedef non_const_context<detail::file_info> non_const_context_base
typedef boost::detail::spinlock mutex_type

Public Functions

file(const std::string &file_name, file_settings set = file_settings())

constructs the file destination

Parameters
  • file_name: name of the file
  • set: [optional] file settings - see file_settings class, and dealing_with_flags

void operator()(const msg_type &msg) const
bool operator==(const file &other) const
void configure(const std::string &str)

configure through script right now, you can only specify the file name

Public Static Attributes

mutex_type mtx_
struct file_settings
#include <file.hpp>

settings for when constructing a file class. To see how it’s used, see dealing_with_flags.

Public Types

typedef hpx::util::logging::detail::flag<file_settings> flag

Public Functions

file_settings()

Public Members

flag::t<bool> flush_each_time

if true (default), flushes after each write

flag::t<bool> initial_overwrite
flag::t<bool> do_append
flag::t<std::ios_base::openmode> extra_flags

just in case you have some extra flags to pass, when opening the file

#include <hpx/logging/format/destination/defaults.hpp>

namespace hpx
namespace util
namespace logging
namespace destination
struct cerr : public is_generic
#include <defaults.hpp>

Writes the string to cerr.

Public Functions

void operator()(const msg_type &msg) const
bool operator==(const cerr&) const
struct cout : public is_generic
#include <defaults.hpp>

Writes the string to console.

Public Functions

void operator()(const msg_type &msg) const
bool operator==(const cout&) const
struct dbg_window : public is_generic
#include <defaults.hpp>

Writes the string to output debug window.

For non-Windows systems, this is the console.

Public Functions

void operator()(const msg_type &msg) const
bool operator==(const dbg_window&) const
struct stream : public is_generic, public non_const_context<std::ostream *>
#include <defaults.hpp>

writes to stream.

Note
: The stream must outlive this object! Or, clear() the stream, before the stream is deleted.

Public Types

typedef std::ostream stream_type
typedef non_const_context<stream_type *> non_const_context_base

Public Functions

stream(stream_type *s)
stream(stream_type &s)
void operator()(const msg_type &msg) const
bool operator==(const stream &other) const
void set_stream(stream_type *p)

resets the stream. Further output will be written to this stream

void clear()

clears the stream. Further output will be ignored