ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
aloxcamp.cpp
1// #################################################################################################
2// alib::lox::detail - ALox Logging Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
7#include "alib_precompile.hpp"
8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14// ====================================== Global Fragment ======================================
19
20#include "ALib.Strings.Vector.H"
21// =========================================== Module ==========================================
22#if ALIB_C20_MODULES
23 module ALib.ALox.Impl;
24 import ALib.ALox;
25 import ALib.Lang;
26 import ALib.EnumOps;
28 import ALib.Strings;
29 import ALib.Boxing;
30 import ALib.EnumRecords;
32 import ALib.Variables;
33 import ALib.Camp;
34 import ALib.Camp.Base;
35#else
36# include "ALib.Lang.H"
37# include "ALib.ALox.H"
38# include "ALib.Containers.List.H"
39# include "ALib.Strings.H"
40# include "ALib.Boxing.H"
42# include "ALib.Variables.H"
43# include "ALib.Camp.H"
44# include "ALib.Camp.Base.H"
45# include "ALib.ALox.H"
46# include "ALib.ALox.Impl.H"
47#endif
48// ====================================== Implementation =======================================
49
50
51namespace alib {
52
54
55//==================================================================================================
56/// This is the \b C++ version of <b>%ALox Logging Library</b>, which has been integrated
57/// as one of many modules into the <b>ALib C++ Class Library</b>.<br>
58///
59/// Please check out the \ref alib_mod_alox "documentation of ALib Module ALox" for more
60/// information.
61//==================================================================================================
62namespace lox {
63
65: Camp( "ALOX" )
66{
67 #if ALIB_DEBUG && !ALIB_DEBUG_ASSERTION_PRINTABLES
68 ALIB_ASSERT_ERROR( this == &ALOX, "ALOX",
69 "Instances of class ALox must not be created. Use singleton alib::ALOX" )
70 #endif
71}
72
74{
75 #if ALOX_DBG_LOG
76 if (Log::DebugLogger != nullptr )
78
80 #endif
81
82 ALIB_ASSERT_ERROR(detail::dbgCountLoxes() == 0, "ALOX", "A Lox remained from the last test" )
83
84 #if ALOX_DBG_LOG
85 new (DEBUG_LOX) Lox( "LOG" );
86 #endif
87}
88
89// #################################################################################################
90// Compilation Flags
91// #################################################################################################
92
93// check the compiler-symbols, give warning once (therefore not in HPP)
94#if !ALOX_DBG_LOG && ALOX_DBG_LOG_CI
95# pragma message ( "Warning: ALox compiler-symbol mismatch: ALOX_DBG_LOG_CI is true, while ALOX_DBG_LOG is false." )
96#endif
97#if !ALOX_REL_LOG && ALOX_REL_LOG_CI
98# pragma message ( "Warning: ALox compiler-symbol mismatch: ALOX_REL_LOG_CI is true, while ALOX_REL_LOG is false" )
99#endif
100
101// #################################################################################################
102// ALox module initialization
103// #################################################################################################
104
106{
108 {
109#if !ALIB_CAMP_OMIT_DEFAULT_RESOURCES
110 resourcePool->BootstrapBulk( ResourceCategory,
111
112 "Var0" , A_CHAR( "1|ALOX/NO_IDE_LOGGER|" "B" ) ,
113 "Var1" , A_CHAR( "2|ALOX/CONSOLE_TYPE|" "S" ) ,
114DOX_MARKER([DOX_VARIABLES_REPLACEMENTS1])
115"Var2", A_CHAR( "3|ALOX/%2/VERBOSITY_WITH_%1|ALOXV"),
116DOX_MARKER([DOX_VARIABLES_REPLACEMENTS1])
117 "Var3" , A_CHAR( "4|ALOX/GLOBAL_SOURCE_PATH_TRIM_RULES|" "S" ) ,
118 "Var4" , A_CHAR( "5|ALOX/%1/SOURCE_PATH_TRIM_RULES|" "S" ) ,
119 "Var5" , A_CHAR( "6|ALOX/%1/DOMAIN_SUBSTITUTION|" "SV;" ) ,
120 "Var6" , A_CHAR( "7|ALOX/%1/PREFIXES|" "S" ) ,
121 "Var7" , A_CHAR( "8|ALOX/%1/DUMP_STATE_ON_EXIT|" "S" ) ,
122 "Var8" , A_CHAR("20|ALOX/%1/AUTO_SIZES|" "ALOXAS" ) ,
123 "Var9" , A_CHAR("21|ALOX/%1/FORMAT|" "ALOXFMI" ) ,
124 "Var10", A_CHAR("22|ALOX/%1/FORMAT_DATE_TIME|" "ALOXFDT" ) ,
125 "Var11", A_CHAR("23|ALOX/%1/FORMAT_MULTILINE|" "ALOXFML" ) ,
126 "Var12", A_CHAR("24|ALOX/%1/FORMAT_TIME_DIFF|" "ALOXFTD" ) ,
127 "Var13", A_CHAR("25|ALOX/%1/FORMAT_OTHER|" "ALOXFO" ) ,
128 "Var14", A_CHAR("26|ALOX/%1/REPLACEMENTS|" "ALOXSR" ) ,
129 "Var15", A_CHAR("27|ALOX/CONSOLE_LIGHT_COLORS|" "ALOXCLP" ) ,
130 "Var16", A_CHAR("28|ALOX/CODEPAGE|" "I" ) ,
131
132 // configuration variable default values
133 "Var_D1", A_CHAR("false"),
134 "Var_D2", A_CHAR("default"),
135 "Var_D8", A_CHAR("none, verbosity=info, domain=/ALOX"),
136
137
138// standard textlogger format string
140 "Var_D21", A_CHAR("%SF:%SL:%A3%SM %A3[%TC +%TL][%tN][%D]%A1#%# %V: ")
141#else
142 "Var_D21", A_CHAR("[%TC +%TL][%tN][%D]%A1#%# %V: ")
143#endif
144 A_CHAR(",[ERR],[WRN], ,[***]") ,
145
146// ANSI textlogger format string
148 "Var_D21A", A_CHAR("%SF:%SL:%A3%SM %A3[%TC +%TL][%tN][%D]%A1#%#: %V")
149#else
150 "Var_D21A", A_CHAR("[%TC +%TL][%tN][%D]%A1#%#:%V")
151#endif
152 A_CHAR( ",\033c0,\033c3,,\033c8,\033[0m" ) ,
153
154 "Var_D22", A_CHAR("yyyy-MM-dd,HH:mm:ss, Days ") ,
155 "Var_D23", A_CHAR("2,ALox: Multi line message follows: ,> ,,nulled,\\r") ,
156
157
158 "Var_D24", A_CHAR("1000" ",--- " ", ns" ", \u00B5s" )
159 A_CHAR(", ms" ", s" ", m" ", h" ", days" ) ,
160
161 "Var_D25", A_CHAR("---, ---, 3"),
162 #if defined(_WIN32)
163 "Var_D28", A_CHAR("65001"),
164 #endif
165
166 // configuration variable comments
167 "Var_C1", A_CHAR("If true, the creation of an additional, ide-specific debug logger is suppressed." "\n"
168 "(In particular suppresses DebugLogger (C#) and VStudioLogger (C++))" ),
169
170 "Var_C2", A_CHAR("Influences the type of console logger to be created by method" "\n"
171 "Lox::CreateConsoleLogger which is also used by Log::AddDebugLogger" "\n"
172 "Possible values are: default, plain, ansi, windows, noqtcreator" ),
173
174 "Var_C3", A_CHAR("The verbosities of logger \"%2\" in lox \"%1\". Supports wildcards for domain paths." "\n"
175 " Format: [ExportAll ;] [[*]domainpath[*] = Verbosity] [;...] " ),
176
177 "Var_C4", A_CHAR("Defines global source path trim rules (applicable for all Lox instances)." "\n"
178 " Format: [ [*]sourcepath [, inclusion, trimoffset, sensitivity, replacement] ] [;...]" ),
179
180 "Var_C5", A_CHAR("Defines source path trim rules for Lox \"%1\". " "\n"
181 " Format: [ [*]sourcepath [, inclusion, trimoffset, sensitivity, replacement] ] [;...]" ),
182
183 "Var_C7", A_CHAR("Prefix strings for log domains of lox \"%1\".\n"
184 " Format: [ [*]domainpath[*] = prefixstring [, inclusion] ] [;...] " ),
185
186 "Var_C8", A_CHAR("Log information about lox \"%1\" on exit. Comma separated list of arguments define" "\n"
187 "verbosity, domain and content of output. Possible values content arguments are:" "\n"
188 " All, " "Basic, " "Version, " "SPTR, " "Loggers, " "Domains, " "InternalDomains" "\n"
189 " ScopeDomains, " "DSR, " "PrefixLogables" "Once, " "LogData, " "ThreadMappings, " "\n"
190 " CompilationFlags." " If NONE is given nothing is dumped." ),
191
192 "Var_C20", A_CHAR("Detected field sizes and tabulator positions of the meta-information portion and the " "\n"
193 "those of the log output, separated by ';'. (These is a generated and temporary values)."),
194
195 "Var_C21", A_CHAR("Meta info format of logger \"%1\", including signatures for verbosity strings and" "\n"
196 "astring added to the end of each log statement." "\n"
197 " Format: MetaInfo,Error,Warning,Info,Verbose,MsgSuffix"),
198
199 "Var_C22", A_CHAR("Date and time format of logger \"%1\"." "\n"
200 " Format: Date,Time,ElapsedDays"),
201
202 "Var_C23", A_CHAR("Multi-line format of logger \"%1\"." "\n"
203 " Format: Mode,Headline,Prefix,Suffix,Delimiter,DelimiterReplacement"),
204
205 "Var_C24", A_CHAR("Time difference entities of logger \"%1\"." "\n"
206 " Format: Minimum,None,Nanos,Micros,Millis,Secs,Mins,Hours, Days"),
207
208 "Var_C25", A_CHAR("Specifies three further format values: 1. A replacement string if no file name is available, \n"
209 "2. A replacement string if no method name is available and 3. The minimum digits of the\n"
210 "log counter." ),
211
212 "Var_C26", A_CHAR("Pairs of search and replacement strings for text logger \"%1\"." "\n"
213 " Format: [search,replacement] [,...]"),
214
215 "Var_C27", A_CHAR("Evaluated by colorful loggers that dispose of light and dark colors. Those may adjust" "\n"
216 "their foreground and background color accordingly. If not given, under Windows OS the right" "\n"
217 "value is detected. Otherwise the value defaults to \"foreground\". In some occasions, the" "\n"
218 "(detected or set) runtime environment might also indicate a different default value." "\n"
219 "Possible values are 'Auto', Foreground', 'Background' and 'Never'."),
220
221 #if defined(_WIN32)
222 "Var_C28", A_CHAR("Code page used by class WindowsConsoleLogger. Defaults to 65001." "\n"
223 "(Only used on Windows OS)" ),
224 #endif
225
226 //###################################### Enums #######################################
227 "Verbosity", A_CHAR("0,Verbose,1,"
228 "1,Info,1,"
229 "2,Warning,1,"
230 "2,Warnings,1," //allow with trailing s when reading
231 "3,Error,1,"
232 "3,Errors,1," //allow with trailing s when reading
233 "4,Off,1" ),
234
235 "Scope", A_CHAR("0,Global,1,"
236 "1,ThreadOuter,7,"
237 "2,Filename,1,"
238 "3,Method,1,"
239 "4,ThreadInner,7,"
240 "5,Path,7" ),
241
242 "StateInfo", A_CHAR("0" "," "NONE" ",1,"
243 "1" "," "Basic" ",1,"
244 "2" "," "Version" ",1,"
245 "^9" "," "LogData" ",4,"
246 "4" "," "Loggers" ",1,"
247 "^6" "," "DSR" ",2,"
248 "8" "," "Domains" ",1,"
249 "^4" "," "InternalDomains" ",1,"
250 "0x100000" "," "SPTR" ",2,"
251 "^5" "," "ScopeDomains" ",1,"
252 "^7" "," "PrefixLogables" ",1,"
253 "^8" "," "Once" ",1,"
254 "^10" "," "ThreadMappings" ",1,"
255 "^21" "," "CompilationFlags" ",1,"
256 "0xFFFFFFFF" "," "All" ",1" ),
257
258 "LCU", A_CHAR( "0,Auto,1,"
259 "1,Never,1,"
260 "2,Foreground,2,"
261 "3,Background,2,"
262 "2,ForeGround,1,"
263 "3,BackGround,1" ),
264
265 //##################################### Various ######################################
266 "VVEA", A_CHAR("ExportAll" ), // Variable VERBOSITIES keyword 'ExportAll'
267 "TLFmtExc", A_CHAR("\nAn exception occurred during formatting ALox logables:\n" ),
268
269 "INI_CMT_ALOX", A_CHAR("@>'/// '@HL-Settings controlling ALox log output.\n@HL-"),
270#if ALIB_DEBUG
271 "INI_CMT_ALOX/LOG", A_CHAR("@>'/// '@HL-Settings of the Lox-instance used with debug-logging.\n@HL-"),
272 "INI_CMT_ALOX/DEBUG_LOGGER", A_CHAR("@>'/// '@HL-Settings of the debug-logger.\n@HL-"),
273#endif
274
275 // end of BootstrapBulk()
276 nullptr );
277#endif // !ALIB_CAMP_OMIT_DEFAULT_RESOURCES
278
279 } // BootstrapPhases::PrepareResources
280
281DOX_MARKER([DOX_VARIABLES_DEFINETYPE3])
282//...
283//...
285{
286 ALIB_VARIABLES_REGISTER_TYPE( FormatMetaInfo )
287 //...
288 //...
289DOX_MARKER([DOX_VARIABLES_DEFINETYPE3])
291 ALIB_VARIABLES_REGISTER_TYPE( FormatDateTime )
292 ALIB_VARIABLES_REGISTER_TYPE( FormatTimeDiff )
293 ALIB_VARIABLES_REGISTER_TYPE( FormatMultiLine )
294 ALIB_VARIABLES_REGISTER_TYPE( FormatOther )
295 ALIB_VARIABLES_REGISTER_TYPE( FormatAutoSizes )
296 ALIB_VARIABLES_REGISTER_TYPE( Replacements )
297 ALIB_VARIABLES_REGISTER_TYPE( ColorfulLoggerParameters )
298
299 // Parse enum records
304 ColorfulLoggerParameters::
305 LightColorUsage >( *this, "LCU" );
306
308
309 // preload all variable with declarations (and without placeholders)
310 config->PreloadVariables<lox::Variables>();
311 }
312
314 {
315 #if ALOX_DBG_LOG
316 if ( !DEBUG_LOX )
318 #endif
319 }
320}
321
322
324{
325 (void) phase;
326 #if ALOX_DBG_LOG
327 if( phase == ShutdownPhases::Destruct )
328 {
329 if ( Log::DebugLogger != nullptr )
331
332 if ( DEBUG_LOX )
334
336 }
337 #endif
338}
339
340
341}} // namespace [alib::lox]
342
343#if !DOXYGEN
344namespace alib { namespace strings {
345void AppendableTraits<Scope,nchar, lang::HeapAllocator>::operator()( TAString<nchar, lang::HeapAllocator>& target, const lox::Scope src )
346{
347 Scope scope= src;
348 int pathLevel= int( scope - Scope::Path );
349 if(pathLevel > 0 )
350 scope= Scope::Path;
351
352 target << "Scope::" << enumrecords::GetRecord(scope).EnumElementName;
353
354 if( pathLevel > 0 )
355 target << '+' << pathLevel;
356}
357
359{
360 target._( NField( src.First, 7, lang::Alignment::Left) );
361 target._( '(' )._( src.Second );
362 target.InsertAt( ")", target.LastIndexOfAny<lang::Inclusion::Exclude>( NDEFAULT_WHITESPACES ) + 1 );
363}
364}}
365
366// CVVerbosities
367namespace alib::variables::detail {
368ALIB_DLL void VMeta_CVVerbosities::imPort(VDATA* data, Configuration&, const StringEscaper& esc, const String& src)
369{
370 auto& cvVerbosities= data->As<alib::lox::CVVerbosities>();
371 auto& exportAllKeyWord= alib::ALOX.GetResource("VVEA");
372 cvVerbosities.ExportAll= false;
373
375 StringVectorMA results(la);
376 esc.UnescapeTokens(results, src, A_CHAR(";"));
377 cvVerbosities.Clear();
378 for( auto& it : results )
379 {
380 Substring value= it;
381 value.ConsumeChar('\n');
382 value.ConsumeChar('\r');
383 value.ConsumeCharFromEnd('\n');
384 value.ConsumeCharFromEnd('\r');
385
386 if( value.Equals<CHK, lang::Case::Ignore>(exportAllKeyWord) )
387 {
388 cvVerbosities.ExportAll= true;
389 continue;
390 }
391 cvVerbosities.Add( value );
392 }
393}
394
395ALIB_DLL void VMeta_CVVerbosities::exPort(VDATA* data, Configuration&, const StringEscaper& esc, AString& dest)
396{
397 auto& cvVerbosities= data->As<alib::lox::CVVerbosities>();
398 auto& exportAllKeyWord= alib::ALOX.GetResource("VVEA");
399 if( cvVerbosities.ExportAll)
400 dest << exportAllKeyWord << " ;" << NEW_LINE;
401
402 if( !cvVerbosities.IsEmpty()) // well, this can only be empty if a user makes mistakes
403 for( auto it= cvVerbosities.begin() ;; )
404 {
405 esc.Escape(*it, dest, A_CHAR(";"));
406
407 if( ++it == cvVerbosities.end() )
408 break;
409
410 dest << " ;";
411 dest << NEW_LINE;
412 }
413}
414} //namespace [alib::variables::detail]
415
416#endif // !DOXYGEN
417
NCString ResourceCategory
Definition camp.inl:113
BootstrapPhases GetBootstrapState()
Definition camp.inl:176
SharedConfiguration config
Definition camp.inl:104
Camp(const NCString &resourceCategory)
Definition camp.inl:120
SPResourcePool resourcePool
Definition camp.inl:95
const String & GetResource(const NString &name)
Definition camp.inl:265
virtual void Bootstrap() override
Implementation of Camp::Bootstrap.
Definition aloxcamp.cpp:105
ALIB_DLL void Reset()
Definition aloxcamp.cpp:73
virtual void Shutdown(ShutdownPhases phase) override
Definition aloxcamp.cpp:323
static ALIB_DLL textlogger::TextLogger * DebugLogger
The debug logger created by AddDebugLogger.
Definition log.inl:40
This class acts as a container for Loggers and provides a convenient interface to logging.
Definition lox.inl:15
#define ALIB_DLL
Definition alib.inl:496
#define A_CHAR(STR)
#define ALIB_VARIABLES_REGISTER_TYPE(CPPName)
#define Log_RemoveDebugLogger()
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1049
#define ALOX_DBG_LOG_CI
Definition prepro.md:53
#define ALOX_REL_LOG_CI
Definition prepro.md:54
#define ALIB_DEBUG
Definition prepro.md:21
void Bootstrap(camp::Camp &camp, const NString &name, character innerDelim=',', character outerDelim=',')
Definition camp.inl:329
const RecordsTraits< TEnum >::Type & GetRecord(TEnum element)
Definition records.inl:188
@ Left
Chooses left alignment.
void Destruct(T &object)
Definition tmp.inl:83
@ Exclude
Chooses exclusion.
void shutdownLoxes()
Internal lox management.
integer dbgCountLoxes()
ALIB_DLL Lox * DEBUG_LOX
ALIB_DLL TMonoAllocator< lang::HeapAllocator > GLOBAL_ALLOCATOR
VData< void * > VDATA
Definition vmeta.inl:45
strings::util::StringEscaper StringEscaper
Type alias in namespace alib.
Definition escaper.inl:199
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
@ Final
The final initialization phase. Here, camps are initializing their custom setup.
Definition camp.inl:35
lox::Scope Scope
Type alias in namespace alib.
strings::util::TStringVector< character, MonoAllocator > StringVectorMA
Type alias in namespace alib.
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
Definition cstring.inl:644
variables::Configuration Configuration
Type alias in namespace alib.
ShutdownPhases
Termination levels usable with Bootstrapping ALib Camps.
Definition camp.inl:42
@ Destruct
The main phase of termination that destructs everything.
Definition camp.inl:46
boxing::Pair< T, U > Pair
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
lox::ALoxCamp ALOX
The singleton instance of ALib Camp class ALoxCamp.
Definition aloxcamp.cpp:53
constexpr NCString NDEFAULT_WHITESPACES
A zero-terminated string of default whitespace characters.
Definition cstring.inl:673
lox::Lox Lox
Type alias in namespace alib.
Definition lox.inl:1446
strings::TField< nchar > NField
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381
monomem::TLocalAllocator< 4 > LocalAllocator4K
Type alias in namespace alib. Allocates 4kB of stack memory.
strings::TSubstring< character > Substring
Type alias in namespace alib.
void operator()(TAString< TChar > &target, const TAppendable &src)