Skip to content
This repository was archived by the owner on Aug 10, 2024. It is now read-only.

Advanced Usage

FloweyTheFlower420 edited this page Dec 16, 2021 · 2 revisions

Transports

To specify where your logs should go, use transports. Two implementations of the transporter class are provided, one for cout and another for file streams. If you need custom outputs, just implement the transporter class. Transporters are registered like this:

logging::logger::get_instance().add_transport<your_transport_type>(level, color)

The level parameter specifies the lowest logging level that will be sent to the transporter (so if the level is logger::INFO, you will receive logger::INFO and logger::WARN, but not logger::DEBUG. The other parameter controls whether or not to have color. This should be true if you want colored output for cout, but should be false for file transports. For custom transporter, this should be determined by you.

Named logging

The logger also has n<level> member functions, which can be used to control the name of the logger.

logging::logger::get_instance().ninfo("MyLoggerName", "Some message");

Logger Ref

Because the logger is a singleton class, sometimes you want "sub loggers" with different names. Use the copyable logger_ref class for this. You can define the name of the logger inside that class, and use it just like a normal logger.

logging::logger_ref my_logger("MyLogger");
my_logger.info("potatoes");

will print

[INFO] [MyLogger]: potatoes

Logging Streams

You can create an output stream by passing in level and the name of the underlying logger_ref. From there, you can (optionally) replace the std::cout streambuf with the streambuf of the logging stream. Be careful to do this after you add your transports, as the cout_transport takes a reference to the std::cout buf.

Clone this wiki locally