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 
63 inline void base_logger_stream::log(const category& category, verbosity eVerbosity, string_view svMessage)
64 {
65  QX_PERF_SCOPE("Log");
66 
67  if (m_bProtectLog)
68  m_pMutex->lock();
69 
70  do_log(category, eVerbosity, svMessage);
71 
72  if (eVerbosity >= m_eMinFlushVerbosity)
73  flush();
74 
75  if (m_bProtectLog)
76  m_pMutex->unlock();
77 }
78 
80 {
81  QX_PERF_SCOPE("Flush");
82 
83  if (m_bProtectLog)
84  m_pMutex->lock();
85 
86  do_flush();
87 
88  if (m_bProtectLog)
89  m_pMutex->unlock();
90 }
91 
92 } // 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
void log(const category &category, verbosity eVerbosity, 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