qxLib
logger_formatters.h
Go to the documentation of this file.
1 /**
2 
3  @file logger_formatters.h
4  @author Khrapov
5  @date 11.01.2026
6  @copyright © Nick Khrapov, 2026. All right reserved.
7 
8 **/
9 #pragma once
10 
13 #include <qx/verbosity.h>
14 
15 #include <chrono>
16 #include <thread>
17 
18 namespace qx
19 {
20 
21 /**
22  @brief Format time string to the buffer
23  @tparam out_it_t - output iterator type
24  @param it - output iterator
25  @param chDateDelimiter - char to use as delimiter in date part
26  @param chTimeDelimiter - char to use as delimiter in time part
27  @param time - time to append
28 **/
29 template<class out_it_t>
30 inline void append_time_string(
31  out_it_t it,
32  char_type chDateDelimiter,
33  char_type chTimeDelimiter,
34  std::chrono::system_clock::time_point time) noexcept;
35 
36 /**
37  @brief Get verbosity prefix
38  @param eVerbosity - message verbosity
39  @retval - verbosity prefix
40 **/
41 constexpr string_view get_verbosity_prefix(verbosity eVerbosity) noexcept;
42 
43 /**
44  @brief The qx style log line formatter
45  @code Examples:
46  [08.01.2026_23:51:41] Time? Is it really that time again?
47  [08.01.2026_23:51:41][CatCore] Time? Is it really that time again?
48 [W][08.01.2026_23:51:41] Time? Is it really that time again?
49 [W][08.01.2026_23:51:41][CatCore] Time? Is it really that time again?
50  @endcode
51  @param category - code category
52  @param eVerbosity - message verbosity
53  @param threadId - thread where the log is called
54  @param messageTime - message creation time
55  @param svFile - file name string
56  @param svFunction - function name string
57  @param nLine - code line number
58  @param sMessage - user message string
59  @retval - the formatted log line (the same object as sMessage)
60 **/
61 inline string format_message_qx(
62  const category& category,
63  verbosity eVerbosity,
64  std::thread::id threadId,
65  std::chrono::system_clock::time_point messageTime,
66  string_view svFile,
67  string_view svFunction,
68  int nLine,
69  string sMessage) noexcept;
70 
71 } // namespace qx
72 
void append_time_string(out_it_t it, char_type chDateDelimiter, char_type chTimeDelimiter, std::chrono::system_clock::time_point time) noexcept
Format time string to the buffer.
string format_message_qx(const category &category, verbosity eVerbosity, std::thread::id threadId, std::chrono::system_clock::time_point messageTime, string_view svFile, string_view svFunction, int nLine, string sMessage) noexcept
constexpr string_view get_verbosity_prefix(verbosity eVerbosity) noexcept
Get verbosity prefix.