qxLib
logger.inl
Go to the documentation of this file.
1 /**
2 
3  @file logger.inl
4  @author Khrapov
5  @date 17.06.2019
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 
10 namespace qx
11 {
12 
13 inline void logger::log(
14  const category& category,
15  verbosity eVerbosity,
16  string_view svFile,
17  string_view svFunction,
18  int nLine,
19  string_view svMessage)
20 {
21  for (auto& stream : m_Streams)
22  stream->log(category, eVerbosity, svFile, svFunction, nLine, svMessage);
23 }
24 
25 template<class... args_t>
26  requires(log_acceptable_args_c<args_t...>)
27 inline void logger::log(
28  const category& category,
29  verbosity eVerbosity,
30  string_view svFile,
31  string_view svFunction,
32  int nLine,
34  args_t&&... args)
35 {
36  const auto sLogMessage = qx::string::static_format(sFormat, std::forward<args_t>(args)...);
37  for (auto& stream : m_Streams)
38  stream->log(category, eVerbosity, svFile, svFunction, nLine, sLogMessage);
39 }
40 
41 inline void logger::flush()
42 {
43  for (auto& stream : m_Streams)
44  stream->flush();
45 }
46 
47 template<sbo_poly_assignable_c<base_logger_stream> stream_t>
48 inline void logger::add_stream(stream_t stream) noexcept
49 {
50  m_Streams.emplace_back(std::move(stream));
51 }
52 
53 inline void logger::reset() noexcept
54 {
55  m_Streams.clear();
56 }
57 
59  const category& category,
60  verbosity eVerbosity,
61  string_view svFile,
62  string_view svFunction) const noexcept
63 {
64  for (const auto& stream : m_Streams)
65  if (stream->get_unit_info(category, eVerbosity, svFile, svFunction))
66  return true;
67 
68  return false;
69 }
70 
71 } // namespace qx
requires static format_acceptable_args_c< char_type, args_t... > basic_string static_format(const format_string_type< std::type_identity_t< args_t >... > sFormat, args_t &&... args)
Create a string by formatting it with the format string and the args.
A category is a class that identifies a particular piece of code. This code can be located in differe...
Definition: category.h:59
void add_stream(stream_t stream) noexcept
Add an output stream to the logger.
Definition: logger.inl:48
void log(const category &category, verbosity eVerbosity, string_view svFile, string_view svFunction, int nLine, string_view svMessage)
Log to all streams.
Definition: logger.inl:13
bool will_any_stream_accept(const category &category, verbosity eVerbosity, string_view svFile, string_view svFunction) const noexcept
Returns true if any of streams will accept this message.
Definition: logger.inl:58
void reset() noexcept
Reset logger and clear all streams.
Definition: logger.inl:53
void flush()
Flush all streams.
Definition: logger.inl:41
requires(same_variadic_args_v< args_t... >) const expr auto coalesce(args_t &&... args)
Coalesce function, C# a ?? b analogue.
Definition: coalesce.inl:57
std::basic_format_string wrapper that performs additional compile time checks
Definition: format_string.h:29