ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
logtools.cpp
1// #################################################################################################
2// alib::lox - 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 ======================================
16
17// =========================================== Module ==========================================
18#if ALIB_C20_MODULES
19 module ALib.ALox;
20 import ALib.Lang;
21 import ALib.Strings;
23 import ALib.Boxing;
24 import ALib.EnumRecords;
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{
47 Tokenizer tknzr;
48 tknzr.TrimChars= "\r";
49 String1K buf;
52 Formatter& formatter= *Formatter::Default;
53 formatter.Reset();
54 try
55 {
56 size_t entryNo= 1;
57 lox.Acquire( ALIB_CALLER_NULLED );
58
59 if( domainPrefix.IsNotNull() ) lox.SetDomain( domainPrefix, Scope::ThreadOuter );
60 if( logPrefix .IsNotNull() ) lox.SetPrefix( logPrefix , Scope::ThreadOuter );
61 for ( auto& entry : e )
62 {
63 formatter.FormatArgs( buf.Reset(), entry );
64
65 lox.Acquire( entry.CI );
66
67 tknzr.Set( buf, '\n' );
68 bool firstLine= true;
69 while( tknzr.HasNext() )
70 {
71 auto& logables= lox.GetLogableContainer();
72 if( firstLine )
73 logables.Add( "{}{}: {!Q[]}", (entry.Type.Integral() >= 0 ? 'E' : 'I'),
74 entryNo, entry.Type );
75 else
76 logables.Add( " {}" , tknzr.Next() );
77
78 lox.Entry( "", verbosity );
79 firstLine= false;
80 }
81 lox.Release();
82 ++entryNo;
83 }
84 if( domainPrefix.IsNotNull() ) lox.SetDomain( nullptr, Scope::ThreadOuter );
85 if( logPrefix .IsNotNull() ) lox.SetPrefix( nullptr, Scope::ThreadOuter );
86 lox.Release();
87 }
88 catch(alib::Exception& )
89 {
90 lox.Error("Format exception caught while creating formatted output of another exception!\n"
91 "Format output generated so far: ", buf );
92 }
93}
94# include "ALib.Lang.CIMethods.H"
95
96
97}}// namespace [alib::lox]
98
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:15
void DbgDisableBufferReplacementWarning()
Definition tastring.inl:245
constexpr bool IsNotNull() const
Definition string.inl:357
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:70
#define ALIB_CALLER_NULLED
Definition alib.inl:1010
#define ALIB_LOCK_RECURSIVE_WITH(lock)
Definition alib.inl:1323
strings::util::TTokenizer< character > Tokenizer
Type alias in namespace alib.
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2390
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:2381