ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
logtools.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 !DOXYGEN
10# include "alib/alox/logtools.hpp"
13#endif // !DOXYGEN
14
15
16namespace alib { namespace lox {
17
19
21 const alib::Exception& e,
22 Verbosity verbosity,
23 const NString& domainPrefix,
24 const String& logPrefix
25 )
26{
27 Tokenizer tknzr;
28 tknzr.TrimChars= "\r";
29 String1K buf;
32 Formatter& formatter= *Formatter::Default;
33 formatter.Reset();
34 try
35 {
36 size_t entryNo= 1;
38
39 if( domainPrefix.IsNotNull() ) lox.SetDomain( domainPrefix, Scope::ThreadOuter );
40 if( logPrefix .IsNotNull() ) lox.SetPrefix( logPrefix , Scope::ThreadOuter );
41 for ( auto& entry : e )
42 {
43 formatter.FormatArgs( buf.Reset(), entry );
44
45 lox.Acquire( entry.CI );
46
47 tknzr.Set( buf, '\n' );
48 bool firstLine= true;
49 while( tknzr.HasNext() )
50 {
51 auto& logables= lox.GetLogableContainer();
52 if( firstLine )
53 logables.Add( "{}{}: {!Q[]}", (entry.Type.Integral() >= 0 ? 'E' : 'I'),
54 entryNo, entry.Type );
55 else
56 logables.Add( " {}" , tknzr.Next() );
57
58 lox.Entry( "", verbosity );
59 firstLine= false;
60 }
61 lox.Release();
62 ++entryNo;
63 }
64 if( domainPrefix.IsNotNull() ) lox.SetDomain( nullptr, Scope::ThreadOuter );
65 if( logPrefix .IsNotNull() ) lox.SetPrefix( nullptr, Scope::ThreadOuter );
66 lox.Release();
67 }
68 catch(alib::Exception& e)
69 {
70 lox.Error("Format exception caught while creating formatted output of another exception!\n"
71 "Format exception information follows:\n" );
72 e.Format( buf.Reset() );
73 lox.Error(buf);
74 }
75}
77
78
79}}// namespace [alib::lox]
80
TBoxes & Add()
Definition boxes.inl:74
ALIB_API AString & Format(AString &target) const
static ALIB_API threads::RecursiveLock DefaultLock
static ALIB_API SPFormatter Default
Formatter & FormatArgs(AString &target)
virtual BoxesMA & Reset()
static ALIB_API void Exception(Lox &lox, const lang::Exception &e, Verbosity verbosity=Verbosity::Error, const NString &domainPrefix="/ERR", const String &logPrefix=A_CHAR(" "))
Definition logtools.cpp:20
This class acts as a container for Loggers and provides a convenient interface to logging.
Definition lox.inl:58
void Error(BoxedObjects &&... logables)
Definition lox.inl:1072
BoxesMA & GetLogableContainer()
Definition lox.inl:937
void Entry(const NString &domain, Verbosity verbosity)
Definition lox.inl:960
void SetPrefix(const Box &prefix, Scope scope)
Definition lox.inl:649
void Release()
Definition lox.inl:167
void SetDomain(const NString &scopeDomain, Scope scope)
Definition lox.inl:469
void Acquire(const lang::CallerInfo &ci)
Definition lox.inl:161
void DbgDisableBufferReplacementWarning()
Definition tastring.inl:363
constexpr bool IsNotNull() const
Definition string.hpp:371
TLocalString< TChar, 8 > TrimChars
Definition tokenizer.hpp:77
ALIB_API TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
Definition tokenizer.cpp:16
void Set(const TString< TChar > &src, TChar delimiter, bool skipEmptyTokens=false)
#define ALIB_CALLER_NULLED
Definition alib.hpp:1173
#define ALIB_LOCK_RECURSIVE_WITH(lock)
Definition owner.hpp:457
Definition alib.cpp:69