ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
logtools.cpp
1//##################################################################################################
2// ALib C++ 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 ========================================
16
17//============================================== Module ============================================
18#if ALIB_C20_MODULES
19 module ALib.ALox;
20 import ALib.Lang;
21 import ALib.Strings;
22 import ALib.Strings.Tokenizer;
23 import ALib.Boxing;
24 import ALib.EnumRecords;
25 import ALib.EnumRecords.Bootstrap;
26 import ALib.Format;
27 import ALib.Variables;
28 import ALib.Camp;
29 import ALib.Camp.Base;
30#else
31# include "ALib.Format.H"
33# include "ALib.ALox.H"
34#endif
35//========================================== Implementation ========================================
36namespace alib { namespace lox {
37
39
41 const alib::Exception& e,
42 Verbosity verbosity,
43 const NString& domainPrefix,
44 const String& logPrefix
45 ) {
46 Tokenizer tknzr;
47 tknzr.TrimChars= "\r";
48 String1K buf;
51 Formatter& formatter= *Formatter::Default;
52 formatter.Reset();
53 try
54 {
55 size_t entryNo= 1;
56 lox.Acquire( ALIB_CALLER_NULLED );
57
58 if( domainPrefix.IsNotNull() ) lox.SetDomain( domainPrefix, Scope::ThreadOuter );
59 if( logPrefix .IsNotNull() ) lox.SetPrefix( logPrefix , Scope::ThreadOuter );
60 for ( auto& entry : e ) {
61 formatter.FormatArgs( buf.Reset(), entry );
62
63 lox.Acquire( entry.CI );
64
65 tknzr.Set( buf, '\n' );
66 bool firstLine= true;
67 while( tknzr.HasNext() ) {
68 auto& logables= lox.GetLogableContainer();
69 if( firstLine )
70 logables.Add( "{}{}: {!Q[]}", (entry.Type.Integral() >= 0 ? 'E' : 'I'),
71 entryNo, entry.Type );
72 else
73 logables.Add( " {}" , tknzr.Next() );
74
75 lox.Entry( "", verbosity );
76 firstLine= false;
77 }
78 lox.Release();
79 ++entryNo;
80 }
81 if( domainPrefix.IsNotNull() ) lox.SetDomain( nullptr, Scope::ThreadOuter );
82 if( logPrefix .IsNotNull() ) lox.SetPrefix( nullptr, Scope::ThreadOuter );
83 lox.Release();
84 }
85 catch(alib::Exception& )
86 {
87 lox.Error("Format exception caught while creating formatted output of another exception!\n"
88 "Format output generated so far: ", buf );
89} }
90# include "ALib.Lang.CIMethods.H"
91
92
93}}// namespace [alib::lox]
static ALIB_DLL threads::RecursiveLock DefaultLock
static ALIB_DLL SPFormatter Default
static ALIB_DLL void Exception(Lox &lox, const exceptions::Exception &e, Verbosity verbosity=Verbosity::Error, const NString &domainPrefix="/ERR", const String &logPrefix=A_CHAR(" "))
Definition logtools.cpp:40
This class acts as a container for Loggers and provides a convenient interface to logging.
Definition lox.inl:14
void DbgDisableBufferReplacementWarning()
Definition tastring.inl:244
constexpr bool IsNotNull() const
Definition string.inl:355
ALIB_DLL TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
Definition tokenizer.cpp:26
void Set(const TString< TChar > &src, TChar delimiter, bool skipEmptyTokens=false)
TLocalString< TChar, 8 > TrimChars
Definition tokenizer.inl:71
#define ALIB_CALLER_NULLED
Definition alib.inl:1027
#define ALIB_LOCK_RECURSIVE_WITH(lock)
Definition alib.inl:1340
strings::util::TTokenizer< character > Tokenizer
Type alias in namespace alib.
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2198
format::Formatter Formatter
Type alias in namespace alib.
LocalString< 1024 > String1K
Type alias name for TLocalString<character,1024>.
exceptions::Exception Exception
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2189