Skip to content

Instantly share code, notes, and snippets.

@catid
Created October 28, 2019 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catid/d858fa43c91f15585c4e17851b809e25 to your computer and use it in GitHub Desktop.
Save catid/d858fa43c91f15585c4e17851b809e25 to your computer and use it in GitHub Desktop.
static void AtExitWrapper()
{
spdlog::info("Terminated");
spdlog::shutdown();
}
void SetupAsyncDiskLog(const std::string& filename)
{
spdlog::init_thread_pool(8192, 1);
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(
filename,
4*1024*1024,
3);
std::vector<spdlog::sink_ptr> sinks {
stdout_sink,
rotating_sink
};
auto logger = std::make_shared<spdlog::async_logger>(
filename,
sinks.begin(), sinks.end(),
spdlog::thread_pool(),
spdlog::async_overflow_policy::overrun_oldest);
//spdlog::async_overflow_policy::block);
spdlog::register_logger(logger);
spdlog::set_default_logger(logger);
spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] %v");
spdlog::set_level(spdlog::level::debug); // Set global log level to debug
// Register an atexit() callback so we do not need manual shutdown in app code
std::atexit(AtExitWrapper);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment