Skip to content
Gabi Melman edited this page Dec 18, 2015 · 51 revisions

###Automatic flush spdlog by default lets the the underlying libc flush whenever it sees fit to achieve good performance.

Use the boolean argument force_flush to indicate the flush to disk policy:

  • false (default): let the underlying libc flush whenever it sees fit - recommended for maximum performance at the cost of delayed writes to the disk, and hence the risk of losing log entries if the application crashes.

  • true: spdlog will flush to disk on every log call - recommended if losing log entries upon a crash is not tolerable, even at the cost of performance.

The following example sets the file logger to automatic flushing by setting the last force_flush argument to true:

auto my_logger = 
    spdlog::rotating_logger_st("my_logger", "filename", 1024*1024*10, 5, true);

###Manual flush You can use the logger->flush() function to instruct a logger to flush its contents. The logger will in turn call the flush() function on each of the underlying sinks.

###Flush interval In asynchronous logging mode only, spdlog supports setting the flush interval in milliseconds.

Set the flush_interval_ms in the set_asynch_mode(..) call, to turn on periodic flush.

Example: Turn on periodic flush interval of 2 seconds:

spdlog::set_async_mode(q_size, spdlog::async_overflow_policy::block_retry,
                       nullptr,
                       std::chrono::seconds(2));