libcaf  0.16.3
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
caf::logger Class Reference

Centrally logs events from all actors in an actor system. More...

#include <logger.hpp>

Inheritance diagram for caf::logger:
caf::ref_counted caf::memory_managed

Classes

struct  config
 Combines various logging-related flags and parameters into a bitfield. More...
 
struct  event
 Encapsulates a single logging event. More...
 
struct  field
 Represents a single format string field. More...
 
class  line_builder
 Utility class for building user-defined log messages with CAF_ARG. More...
 

Public Types

enum  field_type {
  invalid_field,
  category_field,
  class_name_field,
  date_field,
  file_field,
  line_field,
  message_field,
  method_field,
  newline_field,
  priority_field,
  runtime_field,
  thread_field,
  actor_field,
  percent_sign_field,
  plain_text_field
}
 Internal representation of format string entites.
 
using line_format = std::vector< field >
 Stores a parsed format string as list of fields.
 

Public Member Functions

void log (event &&x)
 Writes an entry to the event-queue of the logger. More...
 
actor_id thread_local_aid ()
 Returns the ID of the actor currently associated to the calling thread.
 
actor_id thread_local_aid (actor_id aid)
 Associates an actor ID to the calling thread and returns the last value.
 
bool accepts (unsigned level, atom_value component_name)
 Returns whether the logger is configured to accept input for given component and log level. More...
 
const line_formatfile_format () const
 Returns the output format used for the log file.
 
const line_formatconsole_format () const
 Returns the output format used for the console.
 
unsigned verbosity () const noexcept
 
unsigned file_verbosity () const noexcept
 
unsigned console_verbosity () const noexcept
 
void render (std::ostream &out, const line_format &lf, const event &x) const
 Renders x using the line format lf to out.
 
- Public Member Functions inherited from caf::ref_counted
 ref_counted (const ref_counted &)
 
ref_countedoperator= (const ref_counted &)
 
void ref () const noexcept
 Increases reference count by one.
 
void deref () const noexcept
 Decreases reference count by one and calls request_deletion when it drops to zero. More...
 
bool unique () const noexcept
 Queries whether there is exactly one reference.
 
size_t get_reference_count () const noexcept
 
- Public Member Functions inherited from caf::memory_managed
virtual void request_deletion (bool decremented_rc) const noexcept
 Default implementations calls `delete this, but can be overriden in case deletion depends on some condition or the class doesn't use default new/delete. More...
 

Static Public Member Functions

static void render_fun_prefix (std::ostream &out, const event &x)
 Renders the prefix (namespace and class) of a fully qualified function.
 
static void render_fun_name (std::ostream &out, const event &x)
 Renders the name of a fully qualified function.
 
static void render_time_diff (std::ostream &out, timestamp t0, timestamp tn)
 Renders the difference between t0 and tn in milliseconds.
 
static void render_date (std::ostream &out, timestamp x)
 Renders the date of x in ISO 8601 format.
 
static line_format parse_format (const std::string &format_str)
 Parses format_str into a format description vector. More...
 
static string_view skip_path (string_view filename)
 Skips path in filename.
 
template<class T >
static std::enable_if< std::is_base_of< mixin::subscriber_base, T >::value, std::string >::type joined_groups_of (const T &x)
 Returns a string representation of the joined groups of x if x is an actor with the subscriber mixin. More...
 
template<class T >
static std::enable_if< !std::is_base_of< mixin::subscriber_base, T >::value, const char *>::type joined_groups_of (const T &x)
 Returns a string representation of an empty list if x is not an actor with the subscriber mixin. More...
 
static void set_current_actor_system (actor_system *)
 Stores the actor system for the current thread.
 
static loggercurrent_logger ()
 Returns the logger for the current thread or nullptr if none is registered. More...
 

Static Public Attributes

static constexpr size_t queue_size = 128
 Configures the size of the circular event queue.
 

Friends

class actor_system
 

Additional Inherited Members

- Protected Attributes inherited from caf::ref_counted
std::atomic< size_t > rc_
 

Detailed Description

Centrally logs events from all actors in an actor system.

To enable logging in your application, you need to define CAF_LOG_LEVEL. Per default, the logger generates log4j compatible output.

Member Function Documentation

◆ accepts()

bool caf::logger::accepts ( unsigned  level,
atom_value  component_name 
)

Returns whether the logger is configured to accept input for given component and log level.

◆ current_logger()

static logger* caf::logger::current_logger ( )
static

Returns the logger for the current thread or nullptr if none is registered.

◆ joined_groups_of() [1/2]

template<class T >
static std::enable_if< std::is_base_of<mixin::subscriber_base, T>::value, std::string >::type caf::logger::joined_groups_of ( const T &  x)
static

Returns a string representation of the joined groups of x if x is an actor with the subscriber mixin.

◆ joined_groups_of() [2/2]

template<class T >
static std::enable_if< !std::is_base_of<mixin::subscriber_base, T>::value, const char* >::type caf::logger::joined_groups_of ( const T &  x)
static

Returns a string representation of an empty list if x is not an actor with the subscriber mixin.

◆ log()

void caf::logger::log ( event &&  x)

Writes an entry to the event-queue of the logger.

-safe

◆ parse_format()

static line_format caf::logger::parse_format ( const std::string &  format_str)
static

Parses format_str into a format description vector.

Warning
The returned vector can have pointers into format_str.

The documentation for this class was generated from the following file: