ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
plaintextlogger.cpp
1// #################################################################################################
2// alib::lox::detail - 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_DETAIL_TEXTLOGGER_PLAINTEXTLOGGER)
12#endif
13
14#if !defined (HPP_ALIB_STRINGS_UTIL_TOKENIZER)
16#endif
17#if !defined (HPP_ALIB_CAMP_DIRECTORY)
19#endif
20
21
22#if !defined (HPP_ALIB_ALOX)
23 #include "alib/alox/alox.hpp"
24#endif
25
27#endif // !defined(ALIB_DOX)
28
29
30using namespace alib;
31using namespace alib::lox;
32using namespace alib::lox::detail;
33using namespace alib::lox::detail::textlogger;
34
36 AString& msg,
37 ScopeInfo& , int )
38{
40 return;
41
42 // loop over message, print the parts between the escape sequences
43 integer msgLength= msg.Length();
44 integer start= 0;
45 integer end;
46 integer column= 0;
47 while( start < msgLength )
48 {
49 bool foundESC= true;
50 end= msg.String::IndexOf<false>( '\x1B', start );
51 if( end < 0 )
52 {
53 foundESC= false;
54 end= msgLength ;
55 }
56
57 if( end > start )
58 {
59 integer logWidth= logSubstring( msg, start, end - start );
60 if ( logWidth < 0 )
61 return;
62 column+= logWidth;
63 }
64
65 // interpret escape sequence
66 if ( foundESC )
67 {
68 character c= msg[++end];
69
70 // auto tab or end of meta info part
71 if ( c == 't' || c == 'A')
72 {
73 ++end;
74 c= msg[end++];
75 int extraSpace= c >= '0' && c <= '9' ? c - '0'
76 : c - 'A' + 10;
77
78 integer tabStop= AutoSizes.Next( AutoSizes::Types::Tabstop, column, extraSpace );
79
80 if ( tabStop > column )
81 {
82 auto& spaces= Spaces::Get();
83 integer spacesLength= spaces.Length();
84 integer qty= tabStop - column;
85 while ( qty > 0 )
86 {
87 integer size= qty < spacesLength ? qty : spacesLength;
88 if( logSubstring( spaces, 0, size ) < 0 )
89 return;
90 qty-= size;
91 }
92 column= tabStop;
93 }
94 }
95
96 // prune or ignore all others
97 else
98 {
99 if ( !PruneESCSequences )
100 if( logSubstring( msg, end - 1, 3 ) < 0)
101 return;
102 end+= 2;
103 }
104 }
105
106 // next
107 start= end;
108
109 } // write loop
110
111 ALIB_ASSERT_WARNING( start == msgLength, "ALOX", "Loop error when pruning ESC codes" )
113}
virtual integer logSubstring(const String &buffer, integer start, integer length)=0
virtual bool notifyLogOp(lang::Phase phase)=0
virtual ALIB_API void logText(detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber) override
constexpr integer Length() const
Definition string.hpp:357
@ Tabstop
denotes a tab stop entry.
integer Next(Types type, integer requestedSize, integer growthPadding)
static String & Get(integer minLength=128)
Definition spaces.hpp:58
#define ALIB_ASSERT_WARNING(cond,...)
Definition alib.hpp:985
@ Begin
The start of a transaction.
@ End
The end of a transaction.
Definition alib.cpp:57
characters::character character
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286