Created
October 28, 2019 00:20
-
-
Save catid/d858fa43c91f15585c4e17851b809e25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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