Skip to content

Commit

Permalink
Updated ScribeJsonSupport to define implementations as a trait for ex…
Browse files Browse the repository at this point in the history
…tension and exposed `jsonExtras` to override resulting JSON (Resolves #564)
  • Loading branch information
darkfrog26 committed Mar 19, 2024
1 parent ec5b9a4 commit 24c93ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ trait ScribeJsonSupport[J] {

def logRecord2Json(record: LogRecord): J

def jsonExtras(record: LogRecord, json: J): J = json

def writer(writer: Writer): Writer = new Writer {
override def write(record: LogRecord, output: LogOutput, outputFormat: OutputFormat): Unit = {
val json = logRecord2Json(record)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import io.circe.Json.Null
import io.circe.syntax.EncoderOps
import io.circe.{Json, JsonObject}
import perfolation.long2Implicits
import scribe.{LogRecord, lineSeparator}
import scribe.LogRecord
import scribe.mdc.MDC
import scribe.message.Message
import scribe.throwable.Trace

import io.circe.generic.auto._

object ScribeCirceJsonSupport extends ScribeJsonSupport[Json] {
trait ScribeCirceJsonSupport extends ScribeJsonSupport[Json] {
def json2String(json: Json): String = json.noSpaces

override def logRecord2Json(record: LogRecord): Json = {
Expand All @@ -34,7 +34,7 @@ object ScribeCirceJsonSupport extends ScribeJsonSupport[Json] {
case list => list.toVector.asJson
}
val data = MDC.map ++ record.data
JsonObject(
val json = JsonObject(
"level" -> record.level.name.asJson,
"levelValue" -> record.levelValue.asJson,
"message" -> messages,
Expand All @@ -59,6 +59,9 @@ object ScribeCirceJsonSupport extends ScribeJsonSupport[Json] {
"timeStamp" -> l.asJson,
"date" -> l.t.F.asJson,
"time" -> s"${l.t.T}.${l.t.L}${l.t.z}".asJson
)
}.asJson
).asJson
jsonExtras(record, json)
}
}

object ScribeCirceJsonSupport extends ScribeCirceJsonSupport
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scribe.message.Message
import scribe.throwable.{Trace, TraceElement}
import perfolation._

object ScribeFabricJsonSupport extends ScribeJsonSupport[Json] {
trait ScribeFabricJsonSupport extends ScribeJsonSupport[Json] {
private implicit val traceElementRW: RW[TraceElement] = RW.gen
private implicit val traceRW: RW[Trace] = RW.gen

Expand All @@ -35,7 +35,7 @@ object ScribeFabricJsonSupport extends ScribeJsonSupport[Json] {
case list => Arr(list.toVector)
}
val data = MDC.map ++ record.data
obj(
val json = obj(
"level" -> record.level.name,
"levelValue" -> record.levelValue,
"message" -> messages,
Expand All @@ -61,5 +61,8 @@ object ScribeFabricJsonSupport extends ScribeJsonSupport[Json] {
"date" -> l.t.F,
"time" -> s"${l.t.T}.${l.t.L}${l.t.z}"
)
jsonExtras(record, json)
}
}

object ScribeFabricJsonSupport extends ScribeFabricJsonSupport

0 comments on commit 24c93ef

Please sign in to comment.