ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
logger.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of module \alib_alox of the \aliblong.
4///
5/// Copyright 2013-2026 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
8ALIB_EXPORT namespace alib { namespace lox {
9//==================================================================================================
10/// This is the C++ namespace for internal main classes and other things belonging to
11/// the <em>ALox Logging Library</em>.<p>
12/// Types and interfaces found in this namespace are not designed for access by users of the
13/// library. However, if extending \alox, e.g., by implementing new custom <em>loggers</em>, things
14/// found here provide an important foundation.
15///
16/// Developed by A-Worx GmbH and published under Boost Software License.
17//==================================================================================================
18namespace detail
19{
20class ScopeInfo;
21
22//==================================================================================================
23/// This is a central class of the \alox logging implementation. It is **not** recommended to use this
24/// class directly for logging. Instead, use the simple and convenient static interface class
25/// Log or, for release logging and other more complex operations, use a Lox instance.
26/// The class is abstract. To implement an own log stream, derive a new Logger class and implement
27/// the abstract method #".Log".
28///
29/// ## Friends ##
30/// class #"Lox"
31//==================================================================================================
32class Logger
35#endif
36{
37 #if !DOXYGEN
38 friend struct detail::LoxImpl;
39 friend bool LI::RemoveLogger(LoxImpl*, Logger*);
40 friend Logger* LI::RemoveLogger(LoxImpl*, const NString&);
41 friend void LI::SetVerbosity(LoxImpl*, Logger*, Verbosity, const NString&, Priority);
42 #endif
43
44 //################################################################################################
45 // Internal fields
46 //################################################################################################
47 protected:
48 /// The name of the \e Logger. Used as a reference to a logger. All loggers attached to a
49 /// #"%Lox" have to differ in their names.
50 /// If no name is specified with the constructor, the name will by the same as #".TypeName".
52
53 /// The type name of the \e Logger. This is set by the derived class similar to the class
54 /// name.
56
57 //################################################################################################
58 // public fields
59 //################################################################################################
60 public:
61 /// The number of logs actually performed so far. In a text logger this is similar to the
62 /// line number, despite the fact that a single log call can produce more than one line.
64
65 /// The creation time of the \e Logger.
67
68 /// Timestamp of the last log operation.
70
71 //################################################################################################
72 // Abstract methods
73 //################################################################################################
74 public:
75 /// This is the central method that derived logger classes have to implement to log a
76 /// message. When it is invoked the <em>Log Domain's Verbosity</em> was already checked
77 /// against parameter \p{verbosity}. The only action to take is to perform the log
78 /// itself.<br>
79 /// Parameter \p{logables} contains the objects provided with the log statement as well as
80 /// other objects to log, for example,
81 /// #"alib_mod_alox_prefix_logables_intro;Prefix Logables".
82 ///
83 /// @param dom The <em>Log Domain</em>.
84 /// @param verbosity The verbosity of the message.
85 /// @param logables The list of objects to log.
86 /// @param scope Information about the scope of the <em>Log Statement</em>..
87 virtual void Log( Domain& dom, Verbosity verbosity, BoxesMA& logables, ScopeInfo& scope) =0;
88
89 //################################################################################################
90 // Constructor/Destructor
91 //################################################################################################
92 protected:
93 /// Constructs a logger. This constructor is protected because this class is abstract.
94 ///
95 /// Note: This constructor is implemented in the header and annotated as inline.
96 /// This way, the Log::InitALox call receives the size of classes from the compilation unit
97 /// that invokes the constructor. If different compile options are set, we have a chance to
98 /// detect them here.
99 /// @param name The name of the \e Logger. If empty, it defaults to the type name.
100 /// Will be converted to upper case.
101 /// @param typeName The type of the \e Logger.
102 /// Will be converted to upper case.
103 Logger( const NString& name, const NString& typeName )
104 : Name(name)
105 , TypeName(typeName)
106 , TimeOfCreation ()
107 , TimeOfLastLog () {
108 IF_ALIB_THREADS( ALIB_DBG(Dbg.Name= "Logger";) )
109 if ( Name.IsEmpty() )
110 Name << typeName;
111 Name .ToUpper();
112 TypeName.ToUpper();
113 }
114
115 public:
116 #if ALIB_DEBUG_CRITICAL_SECTIONS
117 /// Destructs a logger
118 virtual ~Logger() override {}
119 #else
120 virtual ~Logger() {}
121 #endif
122
123 //################################################################################################
124 // Registration with class Lox
125 //################################################################################################
126 protected:
127 /// This method is invoked by class #"Lox" when a logger is added or removed from it.
128 /// Note, that a logger might be added to multiple #"%Lox" objects in parallel.
129 ///
130 /// The default implementation of this method is empty.
131 ///
132 /// @param lox The #"%Lox" to acknowledge insertion or removal.
133 /// @param op The operation. Either #"%ContainerOp::Insert" or #"%ContainerOp::Remove".
134 virtual void AcknowledgeLox( LoxImpl* lox, lang::ContainerOp op ) { (void) lox; (void) op; }
135
136 //################################################################################################
137 // Interface
138 //################################################################################################
139 public:
140 /// Returns the name of this logger. The name has to be unique for all \e Loggers attached
141 /// to a #"%Lox".
142 /// @return The loggers name.
143 const NString& GetName() const { return Name; }
144
145 /// Returns the constant type name of this logger. The type name is defined by the class
146 /// and hence provides a sort of runtime type information.
147 /// @return The loggers type name.
148 const NString& GetTypeName() const { return TypeName; }
149}; // class Logger
150
151}} // namespace alib[::lox::detail]
152
153/// Type alias in namespace #"%alib".
155
156} // namespace [alib]
157
158
159
160namespace alib { namespace strings {
161
162// Faking all template specializations of namespace strings for doxygen into namespace
163// strings::APPENDABLES to keep the documentation of namespace string clean!
164#if DOXYGEN
165namespace APPENDABLES {
166#endif
167
168//==================================================================================================
169/// Specialization of functor #"AppendableTraits" for type #"%detail::Logger".
170///
171/// @tparam TChar Character type of the target #"%AString".
172//==================================================================================================
173template<typename TChar>
174struct AppendableTraits<lox::detail::Logger,TChar, lang::HeapAllocator> {
175 /// Writes the name of the logger. In case the type name is different, it will be appended
176 /// in braces.
177 /// @param target The AString to append \p{src} to.
178 /// @param logger The logger to append information for.
180 const lox::detail::Logger& logger ) {
181 target << logger.GetName();
182 if ( !logger.GetName().Equals<NC>( logger.GetTypeName() ) )
183 target << " (" << logger.GetTypeName() << ")";
184 }
185};
186
187#if DOXYGEN
188}
189#endif
190
191}} // namespace [alib::lox::strings]
192
#define IF_ALIB_THREADS(...)
#define ALIB_SINGLE_THREADED
#define ALIB_EXPORT
#define ALIB_DBG(...)
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
const NString & GetName() const
Definition logger.hpp:143
Logger(const NString &name, const NString &typeName)
Definition logger.hpp:103
virtual void Log(Domain &dom, Verbosity verbosity, BoxesMA &logables, ScopeInfo &scope)=0
time::Ticks TimeOfLastLog
Timestamp of the last log operation.
Definition logger.hpp:69
virtual void AcknowledgeLox(LoxImpl *lox, lang::ContainerOp op)
Definition logger.hpp:134
time::Ticks TimeOfCreation
The creation time of the Logger.
Definition logger.hpp:66
virtual ~Logger() override
Destructs a logger.
Definition logger.hpp:118
const NString & GetTypeName() const
Definition logger.hpp:148
bool Equals(const TString< TChar > &rhs) const
Definition string.hpp:515
DbgLockAsserter Dbg
The debug tool instance.
ContainerOp
Denotes standard container operations.
Definition alox.cpp:14
strings::TString< nchar > NString
Type alias in namespace #"%alib".
Definition string.hpp:2174
NLocalString< 32 > NString32
Type alias name for #"TLocalString;TLocalString<nchar,32>".
variables::Priority Priority
Type alias in namespace #"%alib".
lox::detail::Logger Logger
Type alias in namespace #"%alib".
Definition logger.hpp:154
lang::integer integer
Type alias in namespace #"%alib".
Definition integers.hpp:149
boxing::TBoxes< MonoAllocator > BoxesMA
Type alias in namespace #"%alib".
Definition boxes.hpp:192
static bool RemoveLogger(LoxImpl *impl, detail::Logger *logger)
Definition loxpimpl.cpp:517
static void SetVerbosity(LoxImpl *impl, detail::Logger *logger, Verbosity verbosity, const NString &domain, Priority priority)
Definition loxpimpl.cpp:580
void operator()(TAString< TChar, lang::HeapAllocator > &target, const lox::detail::Logger &logger)
Definition logger.hpp:179