36makeLogger(std::string_view name, std::string_view logFile = {}) {
37 std::vector<spdlog::sink_ptr> sinks{
38 std::make_shared<spdlog::sinks::stdout_color_sink_mt>(),
41 if (!logFile.empty()) {
47 sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(
48 std::string(logFile), MaxLogFileBytes, MaxLogFiles));
49 }
catch (
const spdlog::spdlog_ex &e) {
50 spdlog::warn(
"Logging to console only; could not open '{}': {}", logFile,
55 auto logger = std::make_shared<spdlog::logger>(std::string(name),
56 sinks.begin(), sinks.end());
58 logger->set_pattern(
"[%Y-%m-%d %H:%M:%S.%e] [%n] [%^%l%$] %v");
59 logger->set_level(spdlog::level::info);
60 logger->flush_on(spdlog::level::info);
std::shared_ptr< spdlog::logger > makeLogger(std::string_view name, std::string_view logFile={})
Create a logger writing to the console and, if logFile is given, to a rotating file alongside it.