ALib C++ Library
Library Version: 2402 R1
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 !defined(ALIB_DOX)
10#if !defined (HPP_ALOX_LOGTOOLS)
11 #include "alib/alox/logtools.hpp"
12#endif
13
14#if !defined (HPP_ALIB_LANG_FORMAT_FORMATTER)
16#endif
17
18#if !defined (HPP_ALIB_STRINGS_UTIL_TOKENIZER)
20#endif
21#endif // !defined(ALIB_DOX)
22
23namespace alib { namespace lox {
24
25
27 const alib::Exception& e,
28 Verbosity verbosity,
29 const NString& domainPrefix,
30 const String& logPrefix
31 )
32{
33 Tokenizer tknzr;
34 tknzr.TrimChars= "\r";
35 String1K buf;
38 try
39 {
40 size_t entryNo= 1;
42
43 if( domainPrefix.IsNotNull() ) lox.SetDomain( domainPrefix, Scope::ThreadOuter );
44 if( logPrefix .IsNotNull() ) lox.SetPrefix( logPrefix , Scope::ThreadOuter );
45 for ( auto& entry : e )
46 {
47 formatter->FormatArgs( buf.Reset(), entry );
48
49 lox.Acquire( entry.File, entry.Line, entry.Function );
50
51 tknzr.Set( buf, '\n' );
52 bool firstLine= true;
53 while( tknzr.HasNext() )
54 {
55 auto& logables= lox.GetLogableContainer();
56 if( firstLine )
57 logables.Add( "{}{}: {!Q[]}", (entry.Type.Integral() >= 0 ? 'E' : 'I'),
58 entryNo, entry.Type );
59 else
60 logables.Add( " {}" , tknzr.Next() );
61
62 lox.Entry( "", verbosity );
63 firstLine= false;
64 }
65 lox.Release();
66 ++entryNo;
67 }
68 if( domainPrefix.IsNotNull() ) lox.SetDomain( nullptr, Scope::ThreadOuter );
69 if( logPrefix .IsNotNull() ) lox.SetPrefix( nullptr, Scope::ThreadOuter );
70 lox.Release();
71 }
72 catch(alib::Exception& e)
73 {
74 lox.Error("Format exception caught while creating formatted output of another exception!\n"
75 "Format exception information follows:\n" );
76 e.Format( buf.Reset() );
77 lox.Error(buf);
78 }
79
80 formatter->Release();
81}
82
83
84}}// namespace [alib::lox]
ALIB_API AString & Format(AString &target) const
static SPFormatter AcquireDefault(const NCString &dbgFile, int dbgLine, const NCString &dbgFunc)
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:26
void Error(BoxedObjects &&... logables)
Definition lox.inl:1115
void Entry(const NString &domain, Verbosity verbosity)
Definition lox.inl:1003
void SetPrefix(const Box &prefix, Scope scope)
Definition lox.inl:692
void Release()
Definition lox.inl:210
void SetDomain(const NString &scopeDomain, Scope scope)
Definition lox.inl:514
Boxes & GetLogableContainer()
Definition lox.inl:980
void Acquire(const NCString &file, int line, const NCString &func)
Definition lox.inl:201
void DbgDisableBufferReplacementWarning()
Definition astring.hpp:353
constexpr bool IsNotNull() const
Definition string.hpp:402
TLocalString< TChar, 8 > TrimChars
Definition tokenizer.hpp:90
ALIB_API TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
Definition tokenizer.cpp:18
void Set(const TString< TChar > &src, TChar delimiter, bool skipEmptyTokens=false)
#define ALIB_CALLER_NULLED
Definition alib.hpp:846
#define ALIB_CALLER_PRUNED
Definition alib.hpp:845
Definition alib.cpp:57
std::shared_ptr< lang::format::Formatter > SPFormatter