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:
@ -11,6 +11,8 @@ import cats.implicits._
|
||||
|
||||
import docspell.common._
|
||||
|
||||
import io.circe.Json
|
||||
|
||||
case class LogEvent(
|
||||
jobId: Ident,
|
||||
taskName: Ident,
|
||||
@ -19,7 +21,8 @@ case class LogEvent(
|
||||
time: Timestamp,
|
||||
level: LogLevel,
|
||||
msg: String,
|
||||
ex: Option[Throwable] = None
|
||||
ex: Option[Throwable],
|
||||
data: Map[String, Json]
|
||||
) {
|
||||
|
||||
def logLine: String =
|
||||
@ -35,10 +38,11 @@ object LogEvent {
|
||||
group: Ident,
|
||||
jobInfo: String,
|
||||
level: LogLevel,
|
||||
msg: String
|
||||
msg: String,
|
||||
data: Map[String, Json]
|
||||
): F[LogEvent] =
|
||||
Timestamp
|
||||
.current[F]
|
||||
.map(now => LogEvent(jobId, taskName, group, jobInfo, now, level, msg))
|
||||
.map(now => LogEvent(jobId, taskName, group, jobInfo, now, level, msg, None, data))
|
||||
|
||||
}
|
||||
|
@ -29,12 +29,13 @@ object LogSink {
|
||||
}
|
||||
|
||||
def logInternal[F[_]: Sync](e: LogEvent): F[Unit] = {
|
||||
val logger = docspell.logging.getLogger[F]
|
||||
val logger = docspell.logging.getLogger[F](e.taskName.id)
|
||||
val addData: logging.LogEvent => logging.LogEvent =
|
||||
_.data("jobId", e.jobId)
|
||||
.data("task", e.taskName)
|
||||
.data("group", e.group)
|
||||
.data("jobInfo", e.jobInfo)
|
||||
.addData(e.data)
|
||||
|
||||
e.level match {
|
||||
case LogLevel.Info =>
|
||||
|
@ -15,6 +15,9 @@ import docspell.common.{Ident, LogLevel}
|
||||
import docspell.logging
|
||||
import docspell.logging.{Level, Logger}
|
||||
|
||||
/** Background tasks use this logger to emit the log events to a queue. The consumer is
|
||||
* [[LogSink]], which picks up log events in a separate thread.
|
||||
*/
|
||||
object QueueLogger {
|
||||
|
||||
def create[F[_]: Sync](
|
||||
@ -34,7 +37,8 @@ object QueueLogger {
|
||||
group,
|
||||
jobInfo,
|
||||
level2Level(logEvent.level),
|
||||
logEvent.msg()
|
||||
logEvent.msg(),
|
||||
logEvent.data.view.mapValues(f => f()).toMap
|
||||
)
|
||||
.flatMap { ev =>
|
||||
val event =
|
||||
|
Reference in New Issue
Block a user