mirror of https://github.com/sbt/sbt.git
Merge pull request #74 from eed3si9n/wip/json
Store JSON into ObjectEvent
This commit is contained in:
commit
add9bd2f4d
|
|
@ -2,7 +2,7 @@ import Dependencies._
|
|||
import Util._
|
||||
import com.typesafe.tools.mima.core._, ProblemFilters._
|
||||
|
||||
def baseVersion: String = "1.0.0-M19"
|
||||
def baseVersion: String = "1.0.0-M21"
|
||||
def internalPath = file("internal")
|
||||
|
||||
def commonSettings: Seq[Setting[_]] = Seq(
|
||||
|
|
@ -73,6 +73,7 @@ lazy val utilControl = (project in internalPath / "util-control").
|
|||
lazy val utilCollection = (project in internalPath / "util-collection").
|
||||
dependsOn(utilTesting % Test).
|
||||
settings(
|
||||
crossScalaVersions := Seq(scala210, scala211, scala212),
|
||||
commonSettings,
|
||||
Util.keywordsSettings,
|
||||
name := "Util Collection",
|
||||
|
|
|
|||
|
|
@ -263,8 +263,8 @@ class ConsoleAppender private[ConsoleAppender] (
|
|||
}
|
||||
def objectEventToLines(oe: ObjectEvent[_]): Vector[String] =
|
||||
{
|
||||
val tag = oe.tag
|
||||
LogExchange.stringCodec[AnyRef](tag) match {
|
||||
val contentType = oe.contentType
|
||||
LogExchange.stringCodec[AnyRef](contentType) match {
|
||||
case Some(codec) => codec.showLines(oe.message.asInstanceOf[AnyRef]).toVector
|
||||
case _ => Vector(oe.message.toString)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class ManagedLogger(
|
|||
val tag = StringTypeTag[A]
|
||||
LogExchange.getOrElseUpdateJsonCodec(tag.key, implicitly[JsonFormat[A]])
|
||||
// println("logEvent " + tag.key)
|
||||
val entry: ObjectEvent[A] = new ObjectEvent(level, v, channelName, execId, tag.key)
|
||||
val entry: ObjectEvent[A] = ObjectEvent(level, v, channelName, execId, tag.key)
|
||||
xlogger.log(
|
||||
ConsoleAppender.toXLevel(level),
|
||||
new ObjectMessage(entry)
|
||||
|
|
|
|||
|
|
@ -4,12 +4,27 @@ package util
|
|||
|
||||
import sbt.util.Level
|
||||
import sjsonnew.JsonFormat
|
||||
import sjsonnew.support.scalajson.unsafe.Converter
|
||||
import scala.json.ast.unsafe.JValue
|
||||
|
||||
final class ObjectEvent[A](
|
||||
val level: Level.Value,
|
||||
val message: A,
|
||||
val channelName: Option[String],
|
||||
val execId: Option[String],
|
||||
val tag: String
|
||||
val contentType: String,
|
||||
val json: JValue
|
||||
) extends Serializable {
|
||||
}
|
||||
|
||||
object ObjectEvent {
|
||||
def apply[A: JsonFormat](
|
||||
level: Level.Value,
|
||||
message: A,
|
||||
channelName: Option[String],
|
||||
execId: Option[String],
|
||||
contentType: String
|
||||
): ObjectEvent[A] =
|
||||
new ObjectEvent(level, message, channelName, execId, contentType,
|
||||
Converter.toJsonUnsafe(message))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package sbt
|
||||
package internal
|
||||
package util.codec
|
||||
|
||||
import sjsonnew.{ JsonWriter => JW, JsonReader => JR, JsonFormat => JF, _ }
|
||||
import scala.json.ast.unsafe._
|
||||
|
||||
trait JValueFormats { self: sjsonnew.BasicJsonProtocol =>
|
||||
implicit val JNullFormat: JF[JNull.type] = new JF[JNull.type] {
|
||||
def write[J](x: JNull.type, b: Builder[J]) = b.writeNull()
|
||||
def read[J](j: Option[J], u: Unbuilder[J]) = JNull
|
||||
}
|
||||
|
||||
implicit val JBooleanFormat: JF[JBoolean] = project(_.get, (x: Boolean) => JBoolean(x))
|
||||
implicit val JStringFormat: JF[JString] = project(_.value, (x: String) => JString(x))
|
||||
implicit val JNumberFormat: JF[JNumber] = project(x => BigDecimal(x.value), (x: BigDecimal) => JNumber(x.toString))
|
||||
implicit val JArrayFormat: JF[JArray] = project[JArray, Array[JValue]](_.value, JArray(_))
|
||||
|
||||
implicit lazy val JObjectJsonWriter: JW[JObject] = new JW[JObject] {
|
||||
def write[J](x: JObject, b: Builder[J]) = {
|
||||
b.beginObject()
|
||||
x.value foreach (jsonField => JValueFormat.addField(jsonField.field, jsonField.value, b))
|
||||
b.endObject()
|
||||
}
|
||||
}
|
||||
|
||||
implicit lazy val JValueJsonWriter: JW[JValue] = new JW[JValue] {
|
||||
def write[J](x: JValue, b: Builder[J]) = x match {
|
||||
case x: JNull.type => JNullFormat.write(x, b)
|
||||
case x: JBoolean => JBooleanFormat.write(x, b)
|
||||
case x: JString => JStringFormat.write(x, b)
|
||||
case x: JNumber => JNumberFormat.write(x, b)
|
||||
case x: JArray => JArrayFormat.write(x, b)
|
||||
case x: JObject => JObjectJsonWriter.write(x, b)
|
||||
}
|
||||
}
|
||||
|
||||
implicit lazy val JValueJsonReader: JR[JValue] = new JR[JValue] {
|
||||
def read[J](j: Option[J], u: Unbuilder[J]) = ??? // Is this even possible? with no Manifest[J]?
|
||||
}
|
||||
|
||||
implicit lazy val JValueFormat: JF[JValue] = jsonFormat[JValue](JValueJsonReader, JValueJsonWriter)
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ object Dependencies {
|
|||
val sjsonnew = "com.eed3si9n" %% "sjson-new-core" % sjsonnewVersion
|
||||
val sjsonnewScalaJson = "com.eed3si9n" %% "sjson-new-scalajson" % sjsonnewVersion
|
||||
|
||||
def log4jVersion = "2.7"
|
||||
def log4jVersion = "2.8.1"
|
||||
val log4jApi = "org.apache.logging.log4j" % "log4j-api" % log4jVersion
|
||||
val log4jCore = "org.apache.logging.log4j" % "log4j-core" % log4jVersion
|
||||
val log4jSlf4jImpl = "org.apache.logging.log4j" % "log4j-slf4j-impl" % log4jVersion
|
||||
|
|
|
|||
Loading…
Reference in New Issue