Skip to content

Commit

Permalink
spdlog: use info level by default and add log to indicate which env v…
Browse files Browse the repository at this point in the history
…ar to use to change log level
  • Loading branch information
amurzeau committed Aug 29, 2023
1 parent ebf84b6 commit ee56be1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ set(LOG_LEVEL_WARN 3)
set(LOG_LEVEL_ERROR 4)
set(LOG_LEVEL_CRITICAL 5)
set(LOG_LEVEL_OFF 6)
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=${LOG_LEVEL_DEBUG})
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=${LOG_LEVEL_TRACE})

add_subdirectory(damc_common)
add_subdirectory(damc_audio_processing)
Expand Down
13 changes: 12 additions & 1 deletion damc_server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,21 @@ void initializeSpdLog() {
//*/
auto logger = std::make_shared<spdlog::logger>("server", sinks.begin(), sinks.end());
spdlog::set_default_logger(logger);
spdlog::set_level(spdlog::level::debug);
spdlog::set_level(spdlog::level::info);

spdlog::cfg::load_env_levels();

SPDLOG_INFO("Log level: global: {}, console: {}, file: {}",
to_string_view(logger->level()),
to_string_view(console_sink->level()),
to_string_view(file_sink->level()));
SPDLOG_INFO("Set SPDLOG_LEVEL environment variable to change log level");
if(file_sink) {
SPDLOG_INFO("Note: logs above info level are only written to the log file at {}", file_sink->filename());
} else {
SPDLOG_INFO("Note: logs above info level are only written to the log file, but couldn't write to a file");
}

spdlog::flush_every(std::chrono::seconds(10));
}

Expand Down

0 comments on commit ee56be1

Please sign in to comment.