ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
log.cpp
1// #################################################################################################
2// alib::lox - ALox Logging Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
9
10#if !DOXYGEN
11# include "alib/alox/alox.hpp"
15# include "alib/alox/aloxcamp.hpp"
16# if defined(_WIN32) && ALIB_DEBUG
18# endif
19#endif // !DOXYGEN
20
21namespace alib { namespace lox {
22
23using namespace detail;
24
25// #################################################################################################
26// Static fields
27// #################################################################################################
28#if ALOX_DBG_LOG
30
31
32 // #################################################################################################
33 // Auto detection of DEBUG environment
34 // #################################################################################################
35
37 TextLogger* Log::IDELogger = nullptr;
38
41 {
42 static bool recursion= false;
43 if( recursion )
44 return;
45 recursion= true;
46
47 // block recursion caused by log operations in this code
48 if ( DebugLogger != nullptr )
49 {
50 ALIB_WARNING( "ALOX", "Log::AddDebugLogger(): called twice." )
51 recursion= false;
52 return;
53 }
54 DebugLogger= reinterpret_cast<decltype(DebugLogger)>(-1);
55
56 // add a VStudio logger if this is a VStudio debug session
57 #if defined(_MSC_VER) && ALIB_DEBUG
59 {
60 bool createIDELogger;
61 {ALIB_LOCK_WITH(ALOX.GetConfigLock())
62 Variable variable(ALOX, Variables::NO_IDE_LOGGER );
63 createIDELogger= variable.IsNotDefined() || (variable.GetBool() == false);
64 }
65 if(createIDELogger)
66 {
67 IDELogger= new VStudioLogger("IDE_LOGGER");
68
69 // add logger
70 lox->SetVerbosity( IDELogger, Verbosity::Verbose, "/" );
71 lox->SetVerbosity( IDELogger, Verbosity::Warning, Lox::InternalDomains );
72 }
73 }
74 #endif
75
76 // add a default console logger
77 DebugLogger= Lox::CreateConsoleLogger("DEBUG_LOGGER");
78
79 // add logger by setting verbosities
80 lox->SetVerbosity( DebugLogger, Verbosity::Verbose );
81 lox->SetVerbosity( DebugLogger, Verbosity::Warning, Lox::InternalDomains );
82 lox->SetVerbosity( DebugLogger, Verbosity::Warning, "/ALIB" );
83
84 // check various variables, if existed already externally. If not, create them empty or
85 // with debug defaults (only done here, namely for debug logger)
87 // Verbosity: If not, set 'ExportAll' flag
88 Variable variable( ALOX );
89 Box replacements[2]= { "LOG", "DEBUG_LOGGER" };
90 variable.Declare( Variables::VERBOSITY, replacements );
91 if( variable.IsNotDefined() )
92 {
93 (void) variable.Define();
94 variable.Get<CVVerbosities>().ExportAll= true;
95 }
96
97 variable.Declare( Variables::SPTR_LOX , "LOG" ); (void) variable.Define();
98 variable.Declare( Variables::DOMAIN_SUBSTITUTION, "LOG" ); (void) variable.Define();
99 variable.Declare( Variables::PREFIXES , "LOG" ); (void) variable.Define();
100 variable.Declare( Variables::DUMP_STATE_ON_EXIT , "LOG" ); (void) variable.Define();
101 if( dynamic_cast<AnsiConsoleLogger*>(DebugLogger) != nullptr )
102 variable.Declare( Variables::CONSOLE_LIGHT_COLORS ); (void) variable.Define();
103 }
104
105 // replace ALib's ReportWriter by an ALox ReportWriter
107
108 recursion= false;
109 }
110
112 {
113 // remove ALox specific report writer of ALib
115
116 // remove debug logger(s)
118 "Log::RemoveDebugLogger(): no debug logger to remove." )
119
120 if ( DebugLogger != nullptr )
121 {
123
124 delete DebugLogger;
125 DebugLogger= nullptr;
126 }
127
128 #if defined(_WIN32) && ALIB_DEBUG
129 if ( IDELogger != nullptr )
130 {
131 lox->RemoveLogger( IDELogger );
132
133 delete IDELogger;
134 IDELogger= nullptr;
135 }
136 #endif
137 }
138
139
140// #################################################################################################
141// ALib Report Writer installation
142// #################################################################################################
144 {
146 "Log::AddReportWriter(): ALoxReportWriter already created." )
147
148 // replace ALib's default ReportWriter (but only this!) by an ALoxReportWriter
151 }
152
154 {
155 // replace the report writer
156 if ( DebugReportWriter != nullptr )
157 {
159 delete DebugReportWriter;
160 DebugReportWriter= nullptr;
161 }
162 }
164
165#endif // ALOX_DBG_LOG
166
167}}// namespace [alib::lox]
168
threads::SharedLock & GetConfigLock()
Definition camp.hpp:219
ALIB_API void PushWriter(ReportWriter *newWriter)
Definition report.cpp:79
ALIB_API void PopWriter(ReportWriter *checkWriter)
Definition report.cpp:88
static Report & GetDefault()
Definition report.hpp:146
ALIB_API bool IsDebuggerPresent()
static ALIB_API void AddDebugLogger(Lox *lox)
Definition log.cpp:40
static ALIB_API ALoxReportWriter * DebugReportWriter
Definition log.inl:52
static ALIB_API void RemoveDebugLogger(Lox *lox)
Definition log.cpp:111
static ALIB_API textlogger::TextLogger * DebugLogger
The debug logger created by AddDebugLogger.
Definition log.inl:43
static ALIB_API textlogger::TextLogger * IDELogger
An (additional) IDE specific logger, that might be created by AddDebugLogger.
Definition log.inl:46
static ALIB_API void RemoveALibReportWriter()
Removes the report writer created with AddALibReportWriter.
Definition log.cpp:153
static ALIB_API void AddALibReportWriter(Lox *lox)
Definition log.cpp:143
This class acts as a container for Loggers and provides a convenient interface to logging.
Definition lox.inl:58
bool RemoveLogger(detail::Logger *logger)
Definition lox.inl:328
static ALIB_API textlogger::TextLogger * CreateConsoleLogger(const NString &name=nullptr)
static constexpr NString InternalDomains
Definition lox.inl:92
static TDerivedClass & GetSingleton()
Definition singleton.hpp:59
#define ALIB_WARNING(...)
Definition alib.hpp:1268
#define ALIB_ASSERT_WARNING(cond,...)
Definition alib.hpp:1272
#define ALIB_LOCK_WITH(lock)
Definition owner.hpp:456
@ CONSOLE_LIGHT_COLORS
Denotes configuration variable ALOX/CONSOLE_LIGHT_COLORS used by colorful specializations of class Te...
@ VERBOSITY
Denotes configuration variable ALOX/LOGGERNAME/VERBOSITY_WITH_LOXNAME.
@ DOMAIN_SUBSTITUTION
Denotes configuration variable ALOX/LOXNAME/DOMAIN_SUBSTITUTION used by class Lox.
@ DUMP_STATE_ON_EXIT
Denotes configuration variable ALOX/LOXNAME/DUMP_STATE_ON_EXIT used by class Lox.
@ SPTR_LOX
Denotes configuration variable ALOX/LOXNAME/SOURCE_PATH_TRIM_RULES used by class Lox.
@ PREFIXES
Denotes configuration variable ALOX/LOXNAME/PREFIXES used by class Lox.
Definition alib.cpp:69
lox::ALoxCamp ALOX
The singleton instance of ALib Camp class ALoxCamp.
Definition aloxcamp.cpp:33
lox::ALoxReportWriter ALoxReportWriter
Type alias in namespace alib.
lang::basecamp::BaseCamp BASECAMP
The singleton instance of ALib Camp class BaseCamp.
Definition basecamp.cpp:70
lox::textlogger::TextLogger TextLogger
Type alias in namespace alib.
lox::loggers::AnsiConsoleLogger AnsiConsoleLogger
Type alias in namespace alib.