qxLib
base_logger_stream.inl
Go to the documentation of this file.
1 /**
2 
3  @file base_logger_stream.inl
4  @author Khrapov
5  @date 30.07.2021
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 
10 QX_SET_FILE_CATEGORY(CatLogger);
11 
12 namespace qx
13 {
14 
15 namespace details
16 {
17 
18 template<class char_t /* = char */>
19 struct get_cerr
20 {
21  static auto& get() noexcept
22  {
23  return std::cerr;
24  }
25 };
26 
27 template<>
28 struct get_cerr</* class char_t = */ wchar_t>
29 {
30  static auto& get() noexcept
31  {
32  return std::wcerr;
33  }
34 };
35 
36 template<class char_t /* = char */>
37 struct get_cout
38 {
39  static auto& get() noexcept
40  {
41  return std::cout;
42  }
43 };
44 
45 template<>
46 struct get_cout</* class char_t = */ wchar_t>
47 {
48  static auto& get() noexcept
49  {
50  return std::wcout;
51  }
52 };
53 
54 } // namespace details
55 
56 inline base_logger_stream::base_logger_stream(const config& streamConfig) noexcept
57  : m_pMutex(std::make_unique<std::recursive_mutex>())
58  , m_bProtectLog(streamConfig.bProtectLog)
59  , m_eMinFlushVerbosity(streamConfig.eMinFlushVerbosity)
60 {
61 }
62 
64  const category& category,
65  verbosity eVerbosity,
66  std::thread::id threadId,
67  std::chrono::system_clock::time_point messageTime,
68  string_view svFile,
69  string_view svFunction,
70  int nLine,
71  string_view svMessage)
72 {
73  QX_PERF_SCOPE("Log");
74 
75  if (m_bProtectLog)
76  m_pMutex->lock();
77 
78  do_log(category, eVerbosity, threadId, messageTime, svFile, svFunction, nLine, svMessage);
79 
80  if (eVerbosity >= m_eMinFlushVerbosity)
81  flush();
82 
83  if (m_bProtectLog)
84  m_pMutex->unlock();
85 }
86 
88 {
89  QX_PERF_SCOPE("Flush");
90 
91  if (m_bProtectLog)
92  m_pMutex->lock();
93 
94  do_flush();
95 
96  if (m_bProtectLog)
97  m_pMutex->unlock();
98 }
99 
101  const category& category,
102  verbosity eVerbosity,
103  std::thread::id threadId,
104  std::chrono::system_clock::time_point messageTime,
105  string_view svFile,
106  string_view svFunction,
107  int nLine) const noexcept
108 {
109  return false;
110 }
111 
112 } // namespace qx
#define QX_SET_FILE_CATEGORY(_category)
Set the file category You can access this value via QX_GET_FILE_CATEGORY() This category will not be ...
Definition: category.h:29
virtual bool log_unconditionally_required(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
Returns true if this message should be processed by this stream even if the logger filters did not pa...
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, string_view svMessage)
Output to stream.
void flush()
Flush the stream.
base_logger_stream(const config &streamConfig) noexcept
base_logger_stream object constructor
A category is a class that identifies a particular piece of code. This code can be located in differe...
Definition: category.h:59