qxLib
Classes | Public Member Functions | List of all members
qx::logger Class Reference

Logger class. More...

#include <logger.h>

Classes

struct  category_data
 

Public Member Functions

template<sbo_poly_assignable_c< base_logger_stream > stream_t>
void add_stream (stream_t stream) noexcept
 Add an output stream to the logger. More...
 
template<sbo_poly_assignable_c< base_logger_stream > stream_t>
stream_t * get_stream () noexcept
 Get the first occurrence of a stream of the given type. More...
 
template<sbo_poly_assignable_c< base_logger_stream > stream_t>
auto get_streams () noexcept
 Get all the streams of the given type. More...
 
std::shared_mutex & get_streams_mutex () noexcept
 Get streams mutex. More...
 
template<sbo_poly_assignable_c< base_logger_stream > stream_t>
size_t remove_streams () noexcept
 Remove all the streams of the given type. More...
 
void register_category (const category &category, category_data data) noexcept
 Add custom rules for category. More...
 
void register_category (string_view svCategoryName, category_data data) noexcept
 Add custom rules for category. More...
 
void set_default_formatter (format_function_pointer pFormatter) noexcept
 Set a function that will be used as the default formatter in case no formatter found in categories registered. More...
 
virtual void log (const category &category, verbosity eVerbosity, std::thread::id threadId, std::chrono::system_clock::time_point messageTime, string_view svFile, string_view svFunction, int nLine, logger_string_pool::item message)
 Log to all streams. More...
 
virtual void flush ()
 Flush all streams.
 
virtual void reset () noexcept
 Reset logger and clear all streams.
 
flags< message_necessity_type > get_message_necessity_type (const category &category, verbosity eVerbosity, std::thread::id threadId, std::chrono::system_clock::time_point messageTime, string_view svFile, string_view svFunction, int nLine) const noexcept
 Check if this message will go somewhere. More...
 

Detailed Description

Logger class.

Author
Khrapov
Date
10.01.2020

Definition at line 61 of file logger.h.

Member Function Documentation

◆ add_stream()

template<sbo_poly_assignable_c< base_logger_stream > stream_t>
void qx::logger::add_stream ( stream_t  stream)
inlinenoexcept

Add an output stream to the logger.

Template Parameters
stream_t- stream type, derived from base_logger_stream
Parameters
stream- stream object

Definition at line 35 of file logger.inl.

◆ get_message_necessity_type()

flags< logger::message_necessity_type > qx::logger::get_message_necessity_type ( const category category,
verbosity  eVerbosity,
std::thread::id  threadId,
std::chrono::system_clock::time_point  messageTime,
string_view  svFile,
string_view  svFunction,
int  nLine 
) const
inlinenoexcept

Check if this message will go somewhere.

Typically you don't want to use it. It may be useful with async logging to avoid unnecessary formatting and queueing.

Parameters
category- code category
eVerbosity- message verbosity
threadId- thread where the log is called
messageTime- message creation time
svFile- file name string
svFunction- function name string
nLine- code line number
Return values
-get message necessity type

Definition at line 187 of file logger.inl.

◆ get_stream()

template<sbo_poly_assignable_c< base_logger_stream > stream_t>
stream_t * qx::logger::get_stream
inlinenoexcept

Get the first occurrence of a stream of the given type.

Warning
This must be protected with get_streams_mutex() shared lock
Template Parameters
stream_t- stream type to search for
Return values
-stream pointer or nullptr if no stream found

Definition at line 42 of file logger.inl.

◆ get_streams()

template<sbo_poly_assignable_c< base_logger_stream > stream_t>
auto qx::logger::get_streams
inlinenoexcept

Get all the streams of the given type.

Warning
This must be protected with get_streams_mutex() shared lock
Template Parameters
stream_t- stream type to search for
Return values
-streams view

Definition at line 49 of file logger.inl.

◆ get_streams_mutex()

std::shared_mutex & qx::logger::get_streams_mutex ( )
inlinenoexcept

Get streams mutex.

Return values
-streams mutex

Definition at line 59 of file logger.inl.

◆ log()

void qx::logger::log ( const category category,
verbosity  eVerbosity,
std::thread::id  threadId,
std::chrono::system_clock::time_point  messageTime,
string_view  svFile,
string_view  svFunction,
int  nLine,
logger_string_pool::item  message 
)
inlinevirtual

Log to all streams.

Warning
All input args must be ready for async work (i.e. be stable)
Parameters
category- code category
eVerbosity- message verbosity
threadId- thread where the log is called
messageTime- message creation time
svFile- file name string
svFunction- function name string
nLine- code line number
message- user message string

Definition at line 87 of file logger.inl.

◆ register_category() [1/2]

void qx::logger::register_category ( const category category,
category_data  data 
)
inlinenoexcept

Add custom rules for category.

Parameters
category- category to register
data- category data

Definition at line 71 of file logger.inl.

◆ register_category() [2/2]

void qx::logger::register_category ( string_view  svCategoryName,
category_data  data 
)
inlinenoexcept

Add custom rules for category.

Parameters
svCategoryName- category name, must stay valid while the logger is alive (category existence is not checked)
data- category data

Definition at line 76 of file logger.inl.

◆ remove_streams()

template<sbo_poly_assignable_c< base_logger_stream > stream_t>
size_t qx::logger::remove_streams
inlinenoexcept

Remove all the streams of the given type.

Template Parameters
stream_t- stream type to search for
Return values
-number of streams removed

Definition at line 65 of file logger.inl.

◆ set_default_formatter()

void qx::logger::set_default_formatter ( format_function_pointer  pFormatter)
inlinenoexcept

Set a function that will be used as the default formatter in case no formatter found in categories registered.

Parameters
pFormatter- default formatter

Definition at line 82 of file logger.inl.


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