mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Always log to stdout
This commit is contained in:
@ -13,7 +13,6 @@ import docspell.logging.{Level, LogConfig}
|
|||||||
|
|
||||||
import scribe.format.Formatter
|
import scribe.format.Formatter
|
||||||
import scribe.jul.JULHandler
|
import scribe.jul.JULHandler
|
||||||
import scribe.writer.ConsoleWriter
|
|
||||||
|
|
||||||
object ScribeConfigure {
|
object ScribeConfigure {
|
||||||
private[this] val docspellRootVerbose = "DOCSPELL_ROOT_LOGGER_LEVEL"
|
private[this] val docspellRootVerbose = "DOCSPELL_ROOT_LOGGER_LEVEL"
|
||||||
@ -46,13 +45,13 @@ object ScribeConfigure {
|
|||||||
l =>
|
l =>
|
||||||
cfg.format match {
|
cfg.format match {
|
||||||
case Format.Fancy =>
|
case Format.Fancy =>
|
||||||
l.withHandler(formatter = Formatter.enhanced)
|
l.withHandler(formatter = Formatter.enhanced, writer = StdoutWriter)
|
||||||
case Format.Plain =>
|
case Format.Plain =>
|
||||||
l.withHandler(formatter = Formatter.classic)
|
l.withHandler(formatter = Formatter.classic, writer = StdoutWriter)
|
||||||
case Format.Json =>
|
case Format.Json =>
|
||||||
l.withHandler(writer = JsonWriter(ConsoleWriter))
|
l.withHandler(writer = JsonWriter(StdoutWriter))
|
||||||
case Format.Logfmt =>
|
case Format.Logfmt =>
|
||||||
l.withHandler(writer = LogfmtWriter(ConsoleWriter))
|
l.withHandler(writer = LogfmtWriter(StdoutWriter))
|
||||||
},
|
},
|
||||||
_.replace()
|
_.replace()
|
||||||
)
|
)
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 Eike K. & Contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
package docspell.logging.impl
|
||||||
|
|
||||||
|
import scribe._
|
||||||
|
import scribe.output.LogOutput
|
||||||
|
import scribe.output.format.OutputFormat
|
||||||
|
import scribe.writer.Writer
|
||||||
|
|
||||||
|
// From: https://github.com/outr/scribe/blob/8e99521e1ee1f0c421629764dd96e4eb193d84bd/core/shared/src/main/scala/scribe/writer/SystemOutputWriter.scala
|
||||||
|
// Modified to always log to stdout. The original code was logging to stdout and stderr
|
||||||
|
// depending on the log level.
|
||||||
|
// Original code licensed under MIT
|
||||||
|
|
||||||
|
private[impl] object StdoutWriter extends Writer {
|
||||||
|
|
||||||
|
/** If true, will always synchronize writing to the console to avoid interleaved text.
|
||||||
|
* Most native consoles will handle this automatically, but IntelliJ and Eclipse are
|
||||||
|
* notorious about not properly handling this. Defaults to true.
|
||||||
|
*/
|
||||||
|
val synchronizeWriting: Boolean = true
|
||||||
|
|
||||||
|
/** Workaround for some consoles that don't play nicely with asynchronous calls */
|
||||||
|
val alwaysFlush: Boolean = false
|
||||||
|
|
||||||
|
private val stringBuilders = new ThreadLocal[StringBuilder] {
|
||||||
|
override def initialValue(): StringBuilder = new StringBuilder(512)
|
||||||
|
}
|
||||||
|
|
||||||
|
@annotation.nowarn
|
||||||
|
override def write[M](
|
||||||
|
record: LogRecord[M],
|
||||||
|
output: LogOutput,
|
||||||
|
outputFormat: OutputFormat
|
||||||
|
): Unit = {
|
||||||
|
val stream = Logger.system.out
|
||||||
|
val sb = stringBuilders.get()
|
||||||
|
outputFormat.begin(sb.append(_))
|
||||||
|
outputFormat(output, s => sb.append(s))
|
||||||
|
outputFormat.end(sb.append(_))
|
||||||
|
if (synchronizeWriting) {
|
||||||
|
synchronized {
|
||||||
|
stream.println(sb.toString())
|
||||||
|
if (alwaysFlush) stream.flush()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stream.println(sb.toString())
|
||||||
|
if (alwaysFlush) stream.flush()
|
||||||
|
}
|
||||||
|
sb.clear()
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user