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