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