ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
logger.inl
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-2025 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software 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{
20 class 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 \alib{lox;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 /// \b %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 at least one object, the one provided with the log
80 /// statement. Other objects that might be included in the list, are <em>Prefix Objects</em>
81 /// corresponding to the \p{scope}.
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 {
109 IF_ALIB_THREADS( ALIB_DBG(Dbg.Name= "Logger";) )
110 if ( Name.IsEmpty() )
111 Name << typeName;
112 Name .ToUpper();
113 TypeName.ToUpper();
114 }
115
116 public:
117 #if ALIB_DEBUG_CRITICAL_SECTIONS
118 /// Destructs a logger
119 virtual ~Logger() override {}
120 #else
121 virtual ~Logger() {}
122 #endif
123
124 // #############################################################################################
125 // Registration with class Lox
126 // #############################################################################################
127 protected:
128 /// This method is invoked by class \alib{lox;Lox} when a logger is added or removed from it.
129 /// Note, that a logger might be added to multiple \b %Lox objects in parallel.
130 ///
131 /// The default implementation of this method is empty.
132 ///
133 /// @param lox The \b %Lox to acknowledge insertion or removal.
134 /// @param op The operation. Either \b ContainerOp::Insert or \b ContainerOp::Remove.
135 virtual void AcknowledgeLox( LoxImpl* lox, lang::ContainerOp op ) {(void) lox; (void) op; }
136
137 // #############################################################################################
138 // Interface
139 // #############################################################################################
140 public:
141 /// Returns the name of this logger. The name has to be unique for all \e %Loggers attached
142 /// to a \b %Lox.
143 /// @return The loggers name.
144 const NString& GetName() const { return Name; }
145
146 /// Returns the constant type name of this logger. The type name is defined by the class
147 /// and hence provides a sort of run-time type information.
148 /// @return The loggers type name.
149 const NString& GetTypeName() const { return TypeName; }
150
151
152}; // class Logger
153
154}} // namespace alib[::lox::detail]
155
156/// Type alias in namespace \b alib.
158
159} // namespace [alib]
160
161
162
163namespace alib { namespace strings {
164
165// Faking all template specializations of namespace strings for doxygen into namespace
166// strings::APPENDABLES to keep the documentation of namespace string clean!
167#if DOXYGEN
168namespace APPENDABLES {
169#endif
170
171 //==============================================================================================
172 /// Specialization of functor \alib{strings;AppendableTraits} for type \b %Logger.
173 ///
174 /// @tparam TChar Character type of the target \b AString.
175 //==============================================================================================
176 template<typename TChar> struct AppendableTraits<lox::detail::Logger,TChar, lang::HeapAllocator>
177 {
178 /// Writes the name of the logger. In case the type name is different, it will be appended
179 /// in braces.
180 /// @param target The AString to append \p{src} to.
181 /// @param logger The logger to append information for.
183 {
184 target << logger.GetName();
185 if ( !logger.GetName().Equals<NC>( logger.GetTypeName() ) )
186 target << " (" << logger.GetTypeName() << ")";
187 }
188 };
189
190#if DOXYGEN
191}
192#endif
193
194}} // namespace [alib::lox::strings]
195
197
const NString & GetName() const
Definition logger.inl:144
Logger(const NString &name, const NString &typeName)
Definition logger.inl:103
virtual void Log(Domain &dom, Verbosity verbosity, BoxesMA &logables, ScopeInfo &scope)=0
time::Ticks TimeOfLastLog
Timestamp of the last log operation.
Definition logger.inl:69
virtual void AcknowledgeLox(LoxImpl *lox, lang::ContainerOp op)
Definition logger.inl:135
time::Ticks TimeOfCreation
The creation time of the Logger.
Definition logger.inl:66
virtual ~Logger() override
Destructs a logger.
Definition logger.inl:119
const NString & GetTypeName() const
Definition logger.inl:149
bool Equals(const TString< TChar > &rhs) const
Definition string.inl:541
DbgLockAsserter Dbg
The debug tool instance.
#define IF_ALIB_THREADS(...)
Definition alib.inl:401
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
#define ALIB_EXPORT
Definition alib.inl:488
#define ALIB_DBG(...)
Definition alib.inl:836
#define ALIB_SINGLE_THREADED
Definition prepro.md:22
ContainerOp
Denotes standard container operations.
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2390
alib::variables::Priority Priority
Type alias in namespace alib.
boxing::TBoxes< MonoAllocator > BoxesMA
Type alias in namespace alib.
Definition boxes.inl:245
NLocalString< 32 > NString32
Type alias name for TLocalString<nchar,32>.
lox::detail::Logger Logger
Type alias in namespace alib.
Definition logger.inl:157
static ALIB_DLL void SetVerbosity(LoxImpl *impl, detail::Logger *logger, Verbosity verbosity, const NString &domain, Priority priority)
static ALIB_DLL bool RemoveLogger(LoxImpl *impl, detail::Logger *logger)
void operator()(TAString< TChar, lang::HeapAllocator > &target, const lox::detail::Logger &logger)
Definition logger.inl:182