ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
plaintextlogger.cpp
1// #################################################################################################
2// alib::lox::detail - 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.Impl;
20 import ALib.Lang;
22 import ALib.Strings;
23 import ALib.Boxing;
24 import ALib.EnumRecords;
26 import ALib.Variables;
27 import ALib.Camp;
28 import ALib.Camp.Base;
29#else
30# include "ALib.Lang.H"
32# include "ALib.Strings.H"
33# include "ALib.Boxing.H"
35# include "ALib.Variables.H"
36# include "ALib.Camp.H"
37# include "ALib.Camp.Base.H"
38# include "ALib.ALox.H"
39# include "ALib.ALox.Impl.H"
40#endif
41// ====================================== Implementation =======================================
42using namespace alib;
43using namespace alib::lox;
44using namespace alib::lox::detail;
45using namespace alib::lox::textlogger;
46
48 AString& msg,
49 ScopeInfo& , int )
50{
52 return;
53
54 // loop over message, print the parts between the escape sequences
55 integer msgLength= msg.Length();
56 integer start= 0;
57 integer end;
58 integer column= 0;
59 while( start < msgLength )
60 {
61 bool foundESC= true;
62 end= msg.String::IndexOf<NC>( '\x1B', start );
63 if( end < 0 )
64 {
65 foundESC= false;
66 end= msgLength ;
67 }
68
69 if( end > start )
70 {
71 integer logWidth= logSubstring( msg, start, end - start );
72 if ( logWidth < 0 )
73 return;
74 column+= logWidth;
75 }
76
77 // interpret escape sequence
78 if ( foundESC )
79 {
80 character c= msg[++end];
81
82 // auto tab or end of meta info part
83 if ( c == 't' || c == 'A')
84 {
85 ++end;
86 c= msg[end++];
87 int extraSpace= c >= '0' && c <= '9' ? c - '0'
88 : c - 'A' + 10;
89
90 integer tabStop= varFormatAutoSizes.Get<FormatAutoSizes>().Main.Next(
91 AutoSizes::Types::Tabstop, column, extraSpace );
92
93 if ( tabStop > column )
94 {
95 AlignedCharArray spaces( ' ' );
96 integer remaining= tabStop - column;
97 while ( remaining > 0 )
98 {
99 integer size= remaining < spaces.Length() ? remaining
100 : spaces.Length();
101 if( logSubstring( String(spaces.Buffer(), spaces.Length()), 0, size ) < 0 )
102 return;
103 remaining-= size;
104 }
105 column= tabStop;
106 }
107 }
108
109 // prune or ignore all others
110 else
111 {
112 if ( !PruneESCSequences )
113 if( logSubstring( msg, end - 1, 3 ) < 0)
114 return;
115 end+= 2;
116 }
117 }
118
119 // next
120 start= end;
121
122 } // write loop
123
124 ALIB_ASSERT_WARNING( start == msgLength, "ALOX", "Loop error when pruning ESC codes" )
126}
127
virtual bool notifyLogOp(lang::Phase phase)=0
virtual integer logSubstring(const String &buffer, integer start, integer length)=0
virtual ALIB_DLL void logText(detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber) override
constexpr integer Length() const
Definition string.inl:318
@ Tabstop
denotes a tab stop entry.
Definition autosizes.inl:57
#define ALIB_ASSERT_WARNING(cond, domain,...)
Definition alib.inl:1050
@ Begin
The start of a transaction.
@ End
The end of a transaction.
This namespaces defines class TextLogger and its helpers.
Definition loxpimpl.inl:13
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
characters::AlignedCharArray<> AlignedCharArray
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381
characters::character character
Type alias in namespace alib.
constexpr integer Length() const noexcept
constexpr TChar * Buffer() noexcept