ALib C++ Library
Library Version: 2402 R1
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// #################################################################################################
8
9#if !defined(ALIB_DOX)
10# if !defined (HPP_ALIB_ALOX)
11 #include "alib/alox/alox.hpp"
12# endif
13
14# if !defined (HPP_ALOX_VSTUDIO_LOGGER)
16# endif
17
18# if !defined (HPP_ALIB_ALOX_REPORT_WRITER)
20# endif
21
22# if !defined (HPP_ALIB_ALOXMODULE)
24# endif
25
26# if defined(_WIN32) && ALIB_DEBUG && !defined (HPP_ALIB_LANG_BASECAMP)
28# endif
29#endif // !defined(ALIB_DOX)
30
31namespace alib { namespace lox {
32
33using namespace detail;
34
35// #################################################################################################
36// Static fields
37// #################################################################################################
38#if ALOX_DBG_LOG
40
41
42 // #################################################################################################
43 // Auto detection of DEBUG environment
44 // #################################################################################################
45
47 TextLogger* Log::IDELogger = nullptr;
48
49
51 {
52 static bool recursion= false;
53 if( recursion )
54 return;
55 recursion= true;
56
57 // block recursion caused by log operations in this code
58 if ( DebugLogger != nullptr )
59 {
60 ALIB_WARNING( "ALOX", "Log::AddDebugLogger(): called twice." )
61 recursion= false;
62 return;
63 }
64 DebugLogger= reinterpret_cast<decltype(DebugLogger)>(-1);
65
66 // add a VStudio logger if this a VStudio debug session
67 #if defined(_MSC_VER) && ALIB_DEBUG
69 {
71 if( ALOX.GetConfig().Load( variable ) == Priorities::NONE || ! variable.IsTrue() )
72 {
73 IDELogger= new VStudioLogger("IDE_LOGGER");
74
75 // add logger
76 lox->SetVerbosity( IDELogger, Verbosity::Verbose, "/" );
77 lox->SetVerbosity( IDELogger, Verbosity::Warning, Lox::InternalDomains );
78 }
79 }
80 #endif
81
82 // add a default console logger
84
85 // add logger
86 lox->SetVerbosity( DebugLogger, Verbosity::Verbose );
87 lox->SetVerbosity( DebugLogger, Verbosity::Warning, Lox::InternalDomains );
88
89 // replace ALib's ReportWriter by an ALox ReportWriter
91
92 recursion= false;
93 }
94
96 {
97 // remove ALox specific report writer of ALib
99
100 // remove debug logger(s)
102 "Log::RemoveDebugLogger(): no debug logger to remove." )
103
104 if ( DebugLogger != nullptr )
105 {
107
108 delete DebugLogger;
109 DebugLogger= nullptr;
110 }
111
112 #if defined(_WIN32) && ALIB_DEBUG
113 if ( IDELogger != nullptr )
114 {
115 lox->RemoveLogger( IDELogger );
116
117 delete IDELogger;
118 IDELogger= nullptr;
119 }
120 #endif
121 }
122
123
124// #################################################################################################
125// ALib Report Writer installation
126// #################################################################################################
127
129 {
131 "Log::AddReportWriter(): ALoxReportWriter already created." )
132
133 // replace ALib's default ReportWriter (but only this!) by an ALoxReportWriter
136 }
137
139 {
140 // replace the report writer
141 if ( DebugReportWriter != nullptr )
142 {
144 delete DebugReportWriter;
145 DebugReportWriter= nullptr;
146 }
147 }
148
149
150#endif // ALOX_DBG_LOG
151
152}}// namespace [alib::lox]
ALIB_API Priorities Load(Variable &variable)
ALIB_API bool IsTrue(int idx=0)
Definition variable.cpp:242
config::Configuration & GetConfig()
Definition camp.hpp:231
ALIB_API void PushWriter(ReportWriter *newWriter)
Definition report.cpp:93
ALIB_API void PopWriter(ReportWriter *checkWriter)
Definition report.cpp:102
static Report & GetDefault()
Definition report.hpp:157
ALIB_API bool IsDebuggerPresent()
static ALIB_API void AddDebugLogger(Lox *lox)
Definition log.cpp:50
static ALIB_API ALoxReportWriter * DebugReportWriter
Definition log.inl:63
static ALIB_API void RemoveDebugLogger(Lox *lox)
Definition log.cpp:95
static ALIB_API detail::textlogger::TextLogger * DebugLogger
Definition log.inl:53
static ALIB_API detail::textlogger::TextLogger * IDELogger
Definition log.inl:56
static ALIB_API void RemoveALibReportWriter()
Definition log.cpp:138
static ALIB_API void AddALibReportWriter(Lox *lox)
Definition log.cpp:128
bool RemoveLogger(detail::Logger *logger)
Definition lox.inl:375
static ALIB_API detail::textlogger::TextLogger * CreateConsoleLogger(const NString &name=nullptr)
static constexpr NString InternalDomains
Definition lox.inl:121
void SetVerbosity(detail::Logger *logger, Verbosity verbosity, const NString &domain="/", Priorities priority=Priorities::DefaultValues)
Definition lox.inl:454
static TDerivedClass & GetSingleton()
Definition singleton.hpp:61
#define ALIB_WARNING(...)
Definition alib.hpp:981
#define ALIB_ASSERT_WARNING(cond,...)
Definition alib.hpp:985
Definition alib.cpp:57
lox::ALoxReportWriter ALoxReportWriter
Type alias in namespace alib.
lang::basecamp::BaseCamp BASECAMP
Definition basecamp.cpp:136
lox::ALox ALOX
lox::detail::textlogger::TextLogger TextLogger
Type alias in namespace alib.
lox::loggers::VStudioLogger VStudioLogger
Type alias in namespace alib.