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...
 
compile_pattern_result set_default_pattern (string sPattern) noexcept
 Compile and set the default pattern for log messages. More...
 
virtual void log_macro (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)
 Main log function: log to all streams. For macro and internal usage. 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 59 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 36 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 220 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 43 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 50 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 60 of file logger.inl.

◆ log_macro()

void qx::logger::log_macro ( 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

Main log function: log to all streams. For macro and internal usage.

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 93 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 72 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 77 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 66 of file logger.inl.

◆ set_default_pattern()

compile_pattern_result qx::logger::set_default_pattern ( string  sPattern)
inlinenoexcept

Compile and set the default pattern for log messages.

Warning
Not thread safe on purpose due to optimization reasons. Make sure you set it only once before any log line.
Parameters
sPattern- formatting pattern, see qx::logger_specifiers
Return values
-compilation result. If != ok the pattern is unchanged.

Definition at line 83 of file logger.inl.


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