Implements the interface ObjectConverter. Class TextLogger creates an instance of this type in the moment no other (custom) type was set before the first log statement.
This implementation uses two specialisations of class Formatter to format the given logables to a textual representation. The formatters (and their sequence!) are:
This way, standard text logging supports format strings in Python style as well as in Java style.
Definition at line 93 of file textlogger.hpp.
#include <textlogger.hpp>
Public Field Index: | |
std::vector< Formatter * > | Formatters |
Public Method Index: | |
ALIB_API | StandardConverter () |
Constructor. | |
virtual ALIB_API | ~StandardConverter () override |
Virtual destructor. | |
virtual ALIB_API void | ConvertObjects (AString &target, BoxesMA &logables) override |
virtual ALIB_API AutoSizes * | GetAutoSizes () override |
virtual ALIB_API void | ResetAutoSizes () override |
Resets automatically widened tab stops and field widths of this converter. | |
virtual ALIB_API void | SetAutoSizes (AutoSizes *autoSizes) override |
Public Method Index: inherited from ObjectConverter | |
virtual | ~ObjectConverter () |
Destructs an object of this class. | |
Protected Field Index: | |
int | cntRecursion |
A counter to detect recursive calls. | |
|
protected |
A counter to detect recursive calls.
Definition at line 115 of file textlogger.hpp.
std::vector<Formatter*> Formatters |
A list of formatters used to "convert" logables to strings. By default, each entry contains a concatenated pair of formatters of types FormatterPythonStyle and FormatterJavaStyle are added in the constructor of this class.
A vector of formatters is needed to support recursive log calls. If recursion occurs during logging (aka the conversion of a logable triggers another logging operation), necessary formatters are created on the fly, respectively re-used from previous recursions. Their settings are cloned to those of the main formatters using Formatter::CloneSettings.
To use different formatters, it is recommended to implement a different converter type, instead of "patching" the linked and recursive formatters found in this vector.
Definition at line 111 of file textlogger.hpp.
Constructor.
Definition at line 32 of file textlogger.cpp.
|
overridevirtual |
Virtual destructor.
Definition at line 41 of file textlogger.cpp.
The conversion method. Passes target and logables to the Formatters.
target | An AString that takes the result. |
logables | The objects to convert. |
Implements ObjectConverter.
Definition at line 52 of file textlogger.cpp.
|
overridevirtual |
Checks if the first formatter in Formatters is of type FormatterPythonStyle. If so, its AutoSizes member is returned. If not, the method returns nullptr
.
Implements ObjectConverter.
Definition at line 92 of file textlogger.cpp.
|
overridevirtual |
Resets automatically widened tab stops and field widths of this converter.
Implements ObjectConverter.
Definition at line 100 of file textlogger.cpp.
|
overridevirtual |
Checks if the first formatter in Formatters is of type FormatterPythonStyle. If so, its AutoSizes member is set to the given external instance. Otherwise the call is ignored.
autoSizes | The instance to use. |
Implements ObjectConverter.
Definition at line 85 of file textlogger.cpp.