mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
Improve logging configuration
- Log levels of specific loggers can be defined in the config file (doesn't work with env variables) - Log events of background tasks carry now additional data
This commit is contained in:
@ -10,10 +10,26 @@ import cats.data.NonEmptyList
|
||||
|
||||
import io.circe.{Decoder, Encoder}
|
||||
|
||||
final case class LogConfig(minimumLevel: Level, format: LogConfig.Format) {}
|
||||
final case class LogConfig(
|
||||
minimumLevel: Level,
|
||||
format: LogConfig.Format,
|
||||
levels: LogConfig.ExtraLevels
|
||||
) {
|
||||
|
||||
def clearLevels: LogConfig =
|
||||
copy(levels = Map.empty)
|
||||
|
||||
def withLevel(logger: String, level: Level): LogConfig =
|
||||
copy(levels = levels.updated(logger, level))
|
||||
|
||||
def docspellLevel(level: Level): LogConfig =
|
||||
withLevel("docspell", level)
|
||||
}
|
||||
|
||||
object LogConfig {
|
||||
|
||||
type ExtraLevels = Map[String, Level]
|
||||
|
||||
sealed trait Format { self: Product =>
|
||||
def name: String =
|
||||
productPrefix.toLowerCase
|
||||
@ -38,8 +54,10 @@ object LogConfig {
|
||||
}
|
||||
|
||||
implicit val jsonDecoder: Decoder[LogConfig] =
|
||||
Decoder.forProduct2("minimumLevel", "format")(LogConfig.apply)
|
||||
Decoder.forProduct3("minimumLevel", "format", "levels")(LogConfig.apply)
|
||||
|
||||
implicit val jsonEncoder: Encoder[LogConfig] =
|
||||
Encoder.forProduct2("minimumLevel", "format")(r => (r.minimumLevel, r.format))
|
||||
Encoder.forProduct3("minimumLevel", "format", "levels")(r =>
|
||||
(r.minimumLevel, r.format, r.levels)
|
||||
)
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ final case class LogEvent(
|
||||
def data[A: Encoder](key: String, value: => A): LogEvent =
|
||||
copy(data = data.updated(key, () => Encoder[A].apply(value)))
|
||||
|
||||
def addData(m: Map[String, Json]): LogEvent =
|
||||
copy(data = data ++ m.view.mapValues(json => () => json).toMap)
|
||||
|
||||
def addMessage(msg: => String): LogEvent =
|
||||
copy(additional = (() => Left(msg)) :: additional)
|
||||
|
||||
|
Reference in New Issue
Block a user