The logrr_cpp library
The logrr_cpp
library provides the API for sending messages to the log.
The logrr_cpp
library is intended for use in C++ programs. In C-language programs, use the logrr_clog
library.
To get access to the API of this library:
Link your program to the library by using the target_link_libraries()
CMake command.
CMakeLists.txt
Log() method and LOG macro
The logrr::Log()
method writes to the log.
Method parameters:
logLevel
- Log level
LogLevel
. sourceLocation
- Object that determines the location in the source code (file name, function name, line number and column number). The
std::source_location
class is used in C++20, while thestd::experimental::source_location
class is used in earlier versions. format
- Message text formatting string.
args
- Parameters to be inserted into the
format
formatting string.
The logrr::Log()
method is intended for use in C++ programs. In C-language programs, use the static function ClogLog() or CLOG macro.
A description of the logrr::Log()
method and macros for quick access to it are provided in the file /opt/KasperskyOS-Community-Edition-<version>/sysroot-*-kos/include/component/logrr/cpp/logger.h
.
component/logrr/cpp/logger.h (fragment)
A macro for quick access to the Log() method
Instead of calling the static method Logger::Log()
, you can use the macro whose description is provided in the file component/logrr/cpp/logger.h
. This macro is variadic (takes a variable number of parameters), which lets you avoid specifying all parameters of the Logger::Log()
method. When calling this macro, you only need to specify the log level and message formatting string with the values of parameters. The applied log level logLevel
is determined by the first parameter of the macro: An example of using these macros is provided in the section titled Using macros to send messages to a log.
LogLevel class
The LogLevel
class is an enumeration (enum class
) and contains fields whose names correspond to the log levels available in the LogRR
program.
The LogLevel
class is intended for use in C++ programs. In C-language programs, use the enumerated type LogrrLogLevel
.
Values of LogLevel
enumeration can be passed to the following:
- Static method
Log()
of theLogger
class - Static methods
ChangeLogLevel()
andChangeGlobalLogLevel()
of theController
structure LogIface
class constructor
A description of the LogLevel
class is provided in the file /opt/KasperskyOS-Community-Edition-<version>/sysroot-*-kos/include/component/logrr/core/log_level.h
.
component/logrr/core/log_level.h (fragment)
LogIface class
The LogIface
class contains methods that let you incrementally build the text of a log entry from parts and then send the entry to the log with one call:
- The
SetLogLevel()
method is used to set the log level of sent messages. - The
Push()
method is used to add text to a message. - The
Flush()
method is used to send a message composed of one or morePush()
method calls to the log.When the
~LogIface()
destructor is called, the message composed ofPush()
calls is also sent to the log if the message was not previously sent usingFlush()
. - The
Log()
method is used to immediately send a separate message (without using the text composed ofPush()
calls).
To create a LogIface
class instance, pass one of the LogLevel
enumerators to the class constructor. An example of using functions of the LogIface
class is provided in the "Merging messages" subsection under Advanced capabilities when sending messages to a log.
A description of the LogIface
class is provided in the file /opt/KasperskyOS-Community-Edition-<version>/sysroot-*-kos/include/component/logrr/cpp/tools.h
.
component/logrr/cpp/tools.h (fragment)