Skip to content

Commit

Permalink
Merge pull request #223 from GenSpectrum/logsToStdOut
Browse files Browse the repository at this point in the history
feat: also log to stdout
  • Loading branch information
fengelniederhammer authored Nov 2, 2023
2 parents 102e5f8 + 54b8a47 commit a795602
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ RUN apk update && apk add libtbb=2021.7.0-r0 curl jq
HEALTHCHECK --start-period=20s CMD curl --fail --silent localhost:8081/info | jq .sequenceCount | xargs test 0 -ne || exit 1

EXPOSE 8081
ENV SPDLOG_LEVEL="off,file_logger=debug"

ENTRYPOINT ["./siloApi"]
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,13 @@ queries. To execute the tests:

# Logging

We use [spdlog](https://github.com/gabime/spdlog) for logging. The log level and log target can be controlled via
environment variables:
We use [spdlog](https://github.com/gabime/spdlog) for logging.
The log level can be controlled via the environment variable `SPDLOG_LEVEL`:

* Start SILO with `SPDLOG_LEVEL=off,console_logger=debug` to log to stdout at debug level.
* Start SILO with `SPDLOG_LEVEL=off,file_logger=trace` to log to daily rotating files in `log/` (relative from the
location where SILO is executed) at trace level.
* Start SILO with `SPDLOG_LEVEL=off` to turn off logging.
* Start SILO with `SPDLOG_LEVEL=debug` to log at debug level.

If `SPDLOG_LEVEL` is not set, SILO will log to the console at info level.
SILO will log to `./logs/silo_<date>.log` and to stdout.

We decided to use the macros provided by spdlog rather than the functions, because this lets us disable log statements
at compile time by adjusting `add_compile_definitions(SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)` to the desired log level
Expand Down
12 changes: 4 additions & 8 deletions src/silo_api/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ void setupLogger() {
spdlog::cfg::load_env_levels();
spdlog::flush_every(FIVE_SECONDS);

auto file_logger = spdlog::daily_logger_mt(
"file_logger", "logs/silo.log", AT_MIDNIGHT, AT_0_MINUTES, DONT_TRUNCATE, MAX_FILES_7
auto logger = spdlog::daily_logger_mt(
"logger", "logs/silo.log", AT_MIDNIGHT, AT_0_MINUTES, DONT_TRUNCATE, MAX_FILES_7
);
logger->sinks().push_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());

auto console_logger = spdlog::stdout_color_mt("console_logger");
console_logger->flush_on(spdlog::level::trace);

auto default_logger =
file_logger->level() < console_logger->level() ? file_logger : console_logger;
spdlog::set_default_logger(default_logger);
spdlog::set_default_logger(logger);

spdlog::daily_logger_mt(
silo::PERFORMANCE_LOGGER_NAME,
Expand Down

0 comments on commit a795602

Please sign in to comment.