ALib C++ Framework
by
Library Version: 2511 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 #"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 /// \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 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 \b %Lox objects in parallel.
129 ///
130 /// The default implementation of this method is empty.
131 ///
132 /// @param lox The \b %Lox to acknowledge insertion or removal.
133 /// @param op The operation. Either \b ContainerOp::Insert or \b 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 \b %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 run-time type information.
147 /// @return The loggers type name.
148 const NString& GetTypeName() const { return TypeName; }
149
150 /// If the variable is defined with a higher priority than the given one, nothing is done.
151 /// Otherwise, sets the flag #"CVVerbosities::ExportAll" in configuration variable
152 /// to the given value. In the case that parameter \p{value} equals \c true, also an internal
153 /// flag is set, which causes the method #"Variable::IsWriteBack;*" to return
154 /// \c true.
155 /// @param lox The \b %Lox that the logger is attached to.
156 /// Note that a logger might be attached to more than one \b %Lox.
157 /// @param value The value to set.
158 /// @param priority The priority of the setting. Passed to the method
159 /// #"Variable::Define;*".
160 /// @return \c true if the priority was equal or lower than the given one, \c false otherwise.
162 bool SetVerbosityExport(Lox* lox, bool value, Priority priority=Priority::Standard);
163
164}; // class Logger
165
166}} // namespace alib[::lox::detail]
167
168/// Type alias in namespace \b alib.
170
171} // namespace [alib]
172
173
174
175namespace alib { namespace strings {
176
177// Faking all template specializations of namespace strings for doxygen into namespace
178// strings::APPENDABLES to keep the documentation of namespace string clean!
179#if DOXYGEN
180namespace APPENDABLES {
181#endif
182
183//==================================================================================================
184/// Specialization of functor #"AppendableTraits" for type \b %Logger.
185///
186/// @tparam TChar Character type of the target \b AString.
187//==================================================================================================
188template<typename TChar> struct AppendableTraits<lox::detail::Logger,TChar, lang::HeapAllocator>
189{
190 /// Writes the name of the logger. In case the type name is different, it will be appended
191 /// in braces.
192 /// @param target The AString to append \p{src} to.
193 /// @param logger The logger to append information for.
195 const lox::detail::Logger& logger ) {
196 target << logger.GetName();
197 if ( !logger.GetName().Equals<NC>( logger.GetTypeName() ) )
198 target << " (" << logger.GetTypeName() << ")";
199 }
200};
201
202#if DOXYGEN
203}
204#endif
205
206}} // namespace [alib::lox::strings]
207
#define ALIB_DLL
Definition alib.inl:573
#define IF_ALIB_THREADS(...)
Definition alib.inl:466
#define ALIB_SINGLE_THREADED
Definition alib.inl:40
#define ALIB_EXPORT
Definition alib.inl:562
#define ALIB_DBG(...)
Definition alib.inl:931
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
This class acts as a container for Loggers and provides a convenient interface to logging.
Definition lox.inl:14
bool SetVerbosityExport(Lox *lox, bool value, Priority priority=Priority::Standard)
Definition alox.cpp:375
const NString & GetName() const
Definition logger.inl:143
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:134
time::Ticks TimeOfCreation
The creation time of the Logger.
Definition logger.inl:66
virtual ~Logger() override
Destructs a logger.
Definition logger.inl:118
const NString & GetTypeName() const
Definition logger.inl:148
bool Equals(const TString< TChar > &rhs) const
Definition string.inl:519
DbgLockAsserter Dbg
The debug tool instance.
ContainerOp
Denotes standard container operations.
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2181
NLocalString< 32 > NString32
Type alias name for #"TLocalString;TLocalString<nchar,32>".
alib::variables::Priority Priority
Type alias in namespace alib.
lox::detail::Logger Logger
Type alias in namespace alib.
Definition logger.inl:169
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
boxing::TBoxes< MonoAllocator > BoxesMA
Type alias in namespace alib.
Definition boxes.inl:193
static bool RemoveLogger(LoxImpl *impl, detail::Logger *logger)
Definition loxpimpl.cpp:566
static void SetVerbosity(LoxImpl *impl, detail::Logger *logger, Verbosity verbosity, const NString &domain, Priority priority)
Definition loxpimpl.cpp:629
void operator()(TAString< TChar, lang::HeapAllocator > &target, const lox::detail::Logger &logger)
Definition logger.inl:194