Skip to content

Commit

Permalink
chore: Use env variable for root log level (DEV-3410)
Browse files Browse the repository at this point in the history
  • Loading branch information
siers committed Apr 3, 2024
1 parent 1beb192 commit 5488f4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ services:
- knora-net
environment:
- TZ=Europe/Zurich
- LOG_LEVEL=
- KNORA_AKKA_LOGLEVEL=DEBUG
- KNORA_AKKA_STDOUT_LOGLEVEL=DEBUG
- KNORA_WEBAPI_TRIPLESTORE_HOST=db
Expand All @@ -115,6 +116,7 @@ services:
- KNORA_WEBAPI_KNORA_API_EXTERNAL_PORT=3333
- KNORA_WEBAPI_DSP_INGEST_AUDIENCE=http://localhost:3340
- KNORA_WEBAPI_DSP_INGEST_BASE_URL=http://ingest:3340
- DSP_API_LOG_LEVEL=INFO
# - DSP_API_LOG_APPENDER=JSON # if this variable is set, JSON logs are activated locally
deploy:
resources:
Expand Down
14 changes: 10 additions & 4 deletions webapi/src/main/scala/org/knora/webapi/util/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import zio.logging._
import zio.logging.slf4j.bridge.Slf4jBridge

object Logger {
private val envLogLevel = sys.env.getOrElse("DSP_API_LOG_LEVEL", "INFO").toUpperCase

private def rootLogLevel: LogLevel =
LogLevel.levels
.find(_.label == envLogLevel)
.getOrElse(throw new Exception(s"Expected a log level, but found $envLogLevel"))

private val logFilter = LogFilter.LogLevelByNameConfig(
LogLevel.Info,
// Uncomment the following lines to change the log level for specific loggers:
// , ("zio.logging.slf4j", LogLevel.Debug)
// , ("SLF4J-LOGGER", LogLevel.Warning)
rootLogLevel,
// Uncomment the following lines to change the log level for specific loggers:
// , ("zio.logging.slf4j", LogLevel.Debug)
// , ("SLF4J-LOGGER", LogLevel.Warning)
)

private val logFormatText: LogFormat =
Expand Down

0 comments on commit 5488f4a

Please sign in to comment.