Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
Logger.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
5
7
8 /*
9 ********************************************************************************
10 ********************************* Logger ***************************************
11 ********************************************************************************
12 */
13 inline Logger Logger::sThe;
15 {
16 return fMinLogLevel_;
17 }
18 inline void Logger::SetMinLogLevel (Priority minLogLevel)
19 {
20 fMinLogLevel_ = minLogLevel;
21 }
22 inline bool Logger::WouldLog (Priority logLevel) const
23 {
24 return logLevel >= fMinLogLevel_ and not GetAppenders ().empty ();
25 }
26#if !qStroika_Foundation_Debug_DefaultTracingOn
27 inline void Logger::Log (Priority logLevel, const wchar_t* format, ...)
28 {
29 if (WouldLog (logLevel)) {
30 va_list argsList;
31 va_start (argsList, format);
32 String msg = Characters::FormatV (format, argsList);
33 va_end (argsList);
34 Log_ (logLevel, msg);
35 }
36 }
37#endif
38 template <typename CHAR_T, typename... ARGS>
39 inline void Logger::Log (Priority logLevel, const Characters::FormatString<CHAR_T>& fmt, ARGS&&... args)
40 {
41 using namespace Characters::Literals;
42 if (WouldLog (logLevel)) {
43 String msg = fmt (args...);
44 DbgTrace ("Logger::Log ({}, \"{}\")"_f, logLevel, msg);
45 Log_ (logLevel, msg);
46 }
47 else {
48#if qStroika_Foundation_Debug_DefaultTracingOn
49 DbgTrace ("...suppressed by WouldLog: {}"_f, fmt (args...));
50#endif
51 }
52 }
53 template <Characters::IFormatLiteral FORMAT_LITERAL, typename... ARGS>
54 inline void Logger::Log (Priority logLevel, const FORMAT_LITERAL& fmt, ARGS&&... args)
55 {
56 FORMAT_LITERAL::template CheckArgs<ARGS...> ();
57 Log (logLevel, static_cast<const Characters::FormatString<wchar_t>&> (fmt), forward<ARGS> (args)...);
58 }
59
60}
61
63 template <>
64 constexpr EnumNames<Execution::Logger::Priority> DefaultNames<Execution::Logger::Priority>::k{{{
65 {Execution::Logger::Priority::eDebug, L"Debug"},
66 {Execution::Logger::Priority::eInfo, L"Info"},
67 {Execution::Logger::Priority::eNotice, L"Notice"},
68 {Execution::Logger::Priority::eWarning, L"Warning"},
69 {Execution::Logger::Priority::eError, L"Error"},
70 {Execution::Logger::Priority::eCriticalError, L"CriticalError"},
71 {Execution::Logger::Priority::eAlertError, L"AlertError"},
72 {Execution::Logger::Priority::eEmergency, L"Emergency"},
73 }}};
74}
#define DbgTrace
Definition Trace.h:327
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
nonvirtual bool WouldLog(Priority logLevel) const
Definition Logger.inl:22
nonvirtual Priority GetMinLogLevel() const
Definition Logger.inl:14
void Log(Priority logLevel, const wchar_t *format,...)
Definition Logger.inl:27
nonvirtual void SetMinLogLevel(Priority minLogLevel)
Definition Logger.inl:18
nonvirtual Traversal::Iterable< shared_ptr< IAppenderRep > > GetAppenders() const
Definition Logger.cpp:234
String FormatV(const wchar_t *format, va_list argsList)
printf-style formatting of a va_list, into a String - with one difference from vswprintf: s takes a c...
Stroika's format string: it always formats WIDE - each argument as std::formatter<T,...