ALib C++ Library
Library Version: 2412 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/// \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8#ifndef HPP_ALIB_LOX_DETAIL_LOGGER
9#define HPP_ALIB_LOX_DETAIL_LOGGER 1
10#pragma once
11#if !defined(DOXYGEN)
12# include "alib/alib.hpp"
13#endif
14
15#include "alib/alox/alox.hpp"
17#if ALIB_THREADS
19#endif
20namespace alib {
21
22namespace config { class Variable; }
23
24namespace lox {
25//==================================================================================================
26/// This is the C++ namespace for internal main classes and other things belonging to
27/// the <em>%ALox Logging Library</em>.<p>
28/// Types and interfaces found in this namespace are not designed for access by users of the
29/// library. However, if extending \alox, e.g., by implementing new custom <em>loggers</em>, things
30/// found here provide an important foundation.
31///
32/// Developed by A-Worx GmbH and published under Boost Software License.
33//==================================================================================================
34namespace detail
35{
36
37// forward declarations
38class Domain;
39class ScopeInfo;
40struct LoxImpl;
41
42
43//==================================================================================================
44/// This is a central class of the \alox logging implementation. It is **not** recommended to use this
45/// class directly for logging. Instead, use the simple and convenient static interface class
46/// Log or, for release logging and other more complex operations, use a Lox instance.
47/// The class is abstract. To implement an own log stream, derive a new Logger class and implement
48/// the abstract method #Log.
49///
50/// ## Friends ##
51/// class \alib{lox;Lox}
52//==================================================================================================
53class Logger
56#endif
57{
58 #if !DOXYGEN
59 friend struct detail::LoxImpl;
60 friend bool LI::RemoveLogger(LoxImpl*, Logger*);
61 friend Logger* LI::RemoveLogger(LoxImpl*, const NString&);
62 friend void LI::SetVerbosity(LoxImpl*, Logger*, Verbosity, const NString&, Priority);
63 #endif
64
65 // #############################################################################################
66 // Internal fields
67 // #############################################################################################
68 protected:
69 /// The name of the \e Logger. Used as a reference to a logger. All loggers attached to a
70 /// \b %Lox have to differ in their names.
71 /// If no name is specified with the constructor, the name will by the same as #TypeName.
73
74 /// The type name of the \e Logger. This is set by the derived class similar to the class
75 /// name.
77
78 // #############################################################################################
79 // public fields
80 // #############################################################################################
81 public:
82 /// The number of logs actually performed so far. In a text logger this is similar to the
83 /// line number, despite the fact that a single log call can produce more than one line.
85
86 /// The creation time of the \e Logger.
88
89 /// Timestamp of the last log operation.
91
92 // #############################################################################################
93 // Abstract methods
94 // #############################################################################################
95 public:
96 //==========================================================================================
97 /// This is the central method that derived logger classes have to implement to log a
98 /// message. When it is invoked the <em>%Log %Domain's %Verbosity</em> was already checked
99 /// against parameter \p{verbosity}. The only action to take is to perform the log
100 /// itself.<br>
101 /// Parameter \p{logables} contains at least one object, the one provided with the log
102 /// statement. Other objects that might be included in the list, are <em>Prefix Objects</em>
103 /// corresponding to the \p{scope}.
104 ///
105 /// @param dom The <em>Log Domain</em>.
106 /// @param verbosity The verbosity of the message.
107 /// @param logables The list of objects to log.
108 /// @param scope Information about the scope of the <em>Log Statement</em>..
109 //==========================================================================================
110 virtual void Log( Domain& dom, Verbosity verbosity, BoxesMA& logables, ScopeInfo& scope) =0;
111
112 // #############################################################################################
113 // Constructor/Destructor
114 // #############################################################################################
115 protected:
116 //==========================================================================================
117 /// Constructs a logger. This constructor is protected because this class is abstract.
118 ///
119 /// Note: This constructor is implemented in the header and annotated as inline.
120 /// This way, the Log::InitALox call receives the size of classes from the compilation unit
121 /// that invokes the constructor. If different compile options are set, we have a chance to
122 /// detect them here.
123 /// @param name The name of the \e Logger. If empty, it defaults to the type name.
124 /// Will be converted to upper case.
125 /// @param typeName The type of the \e Logger.
126 /// Will be converted to upper case.
127 //==========================================================================================
128 Logger( const NString& name, const NString& typeName )
129 : Name(name)
130 , TypeName(typeName)
131 , TimeOfCreation ()
132 , TimeOfLastLog ()
133 {
134 IF_ALIB_THREADS( ALIB_DBG(Dbg.Name= "Logger";) )
135 if ( Name.IsEmpty() )
136 Name << typeName;
137 Name .ToUpper();
139 }
140
141 public:
142 #if ALIB_DEBUG_CRITICAL_SECTIONS
143 //==========================================================================================
144 /// Destructs a logger
145 //==========================================================================================
146 virtual ~Logger() override {}
147 #else
148 virtual ~Logger() {}
149 #endif
150
151 // #############################################################################################
152 // Registration with class Lox
153 // #############################################################################################
154 protected:
155 /// This method is invoked by class \alib{lox;Lox} when a logger is added or removed from it.
156 /// Note, that a logger might be added to multiple \b %Lox objects in parallel.
157 ///
158 /// The default implementation of this method is empty.
159 ///
160 /// @param lox The \b %Lox to acknowledge insertion or removal.
161 /// @param op The operation. Either \b ContainerOp::Insert or \b ContainerOp::Remove.
162 virtual void AcknowledgeLox( LoxImpl* lox, lang::ContainerOp op )
163 {(void) lox; (void) op; }
164 // #############################################################################################
165 // Interface
166 // #############################################################################################
167 public:
168 //==========================================================================================
169 /// Returns the name of this logger. The name has to be unique for all \e %Loggers attached
170 /// to a \b %Lox.
171 /// @return The loggers name.
172 //==========================================================================================
173 const NString& GetName() const { return Name; }
174
175 //==========================================================================================
176 /// Returns the constant type name of this logger. The type name is defined by the class
177 /// and hence provides a sort of run-time type information.
178 /// @return The loggers type name.
179 //==========================================================================================
180 const NString& GetTypeName() const { return TypeName; }
181
182
183}; // class Logger
184
185}} // namespace alib[::lox::detail]
186
187/// Type alias in namespace \b alib.
189
190} // namespace [alib]
191
192
193
194namespace alib { namespace strings {
195
196// Faking all template specializations of namespace strings for doxygen into namespace
197// strings::APPENDABLES to keep the documentation of namespace string clean!
198#if DOXYGEN
199namespace APPENDABLES {
200#endif
201
202 //==============================================================================================
203 /// Specialization of functor \alib{strings;T_Append} for type \b %Logger.
204 ///
205 /// @tparam TChar Character type of the \b AString to append info about this logger to.
206 /// (Templated inline implementation for all the
207 /// \ref alib_characters_chars "six possible character types".)
208 //==============================================================================================
209 template<typename TChar> struct T_Append<lox::detail::Logger,TChar, lang::HeapAllocator>
210 {
211 //==========================================================================================
212 /// Writes the name of the logger. In case the type name is different, it will be appended
213 /// in braces.
214 ///
215 /// @param target The AString to append \p{src} to.
216 /// @param logger The logger to append information for.
217 //==========================================================================================
219 {
220 target << logger.GetName();
221 if ( !logger.GetName().Equals<NC>( logger.GetTypeName() ) )
222 target << " (" << logger.GetTypeName() << ")";
223 }
224 };
225
226#if DOXYGEN
227}
228#endif
229
230}} // namespace [alib::lox::strings]
231
233
234#endif // HPP_ALIB_LOX_DETAIL_LOGGER
235
virtual ~Logger() override
Destructs a logger.
Definition logger.hpp:146
const NString & GetTypeName() const
Definition logger.hpp:180
Logger(const NString &name, const NString &typeName)
Definition logger.hpp:128
virtual void AcknowledgeLox(LoxImpl *lox, lang::ContainerOp op)
Definition logger.hpp:162
const NString & GetName() const
Definition logger.hpp:173
time::Ticks TimeOfCreation
The creation time of the Logger.
Definition logger.hpp:87
time::Ticks TimeOfLastLog
Timestamp of the last log operation.
Definition logger.hpp:90
virtual void Log(Domain &dom, Verbosity verbosity, BoxesMA &logables, ScopeInfo &scope)=0
TAString & ToUpper(integer regionStart=0, integer regionLength=MAX_LEN)
constexpr bool IsEmpty() const
Definition string.hpp:383
bool Equals(const TString< TChar > &rhs) const
Definition string.hpp:580
DbgLockAsserter Dbg
The debug tool instance.
#define IF_ALIB_THREADS(...)
Definition alib.hpp:352
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
Definition vtable.inl:460
#define ALIB_DBG(...)
Definition alib.hpp:390
#define ALIB_THREADS
Definition alib.hpp:213
ContainerOp
Denotes standard container operations.
Definition alib.cpp:69
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:273
static ALIB_API void SetVerbosity(LoxImpl *impl, detail::Logger *logger, Verbosity verbosity, const NString &domain, Priority priority)
Definition loxpimpl.cpp:661
static ALIB_API bool RemoveLogger(LoxImpl *impl, detail::Logger *logger)
Definition loxpimpl.cpp:594
void operator()(TAString< TChar, lang::HeapAllocator > &target, const lox::detail::Logger &logger)
Definition logger.hpp:218