Cpp Logger is a logging library written in C++ that can be used to log messages of varying severity levels, including DEBUG, INFO, WARNING, and ERROR. The library allows you to customize the logging output format and comes with several pre-defined output sinks that include console, file, and syslog. Cpp Logger also supports multi-threaded environments and provides thread-safe logging.
Here are some code examples using Cpp Logger:
Example 1: Simple logging
```c++ #include
void foo() { LOG(INFO) << "This is an informational message"; LOG(WARNING) << "This is a warning message"; LOG(ERROR) << "This is an error message"; }
In this example, three different logging messages are created using the `LOG` macro and different severity levels - INFO, WARNING, and ERROR. The messages will be logged to the default console output sink.
Example 2: Custom output sink
c++
#include
#include
void bar()
{
std::shared_ptr file_sink = std::make_shared("my_log.txt");
logger::Logger::registerSink(file_sink);
LOG(INFO) << "This message will be logged to a file";
}
```
In this example, a custom file sink is created using the `FileSink` class provided by Cpp Logger. The sink is then registered with the logger using the `registerSink` method. Finally, an INFO-level message is created and logged, which will be written to the specified log file.
Cpp Logger is a standalone package library, and its source code can be downloaded from its Github repository: https://github.com/gabime/spdlog.
C++ (Cpp) Logger - 30 examples found. These are the top rated real world C++ (Cpp) examples of Logger extracted from open source projects. You can rate examples to help us improve the quality of examples.