当前位置: 首页>>代码示例>>Scala>>正文


Scala ILoggingEvent类代码示例

本文整理汇总了Scala中ch.qos.logback.classic.spi.ILoggingEvent的典型用法代码示例。如果您正苦于以下问题:Scala ILoggingEvent类的具体用法?Scala ILoggingEvent怎么用?Scala ILoggingEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ILoggingEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: SplunkHecJsonLayout

//设置package包名称以及导入依赖的类
package io.policarp.logback

import ch.qos.logback.classic.pattern._
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.LayoutBase
import io.policarp.logback.json.{ BaseJson, FullEventJson }
import org.json4s.native.Serialization._

import scala.beans.BeanProperty
import scala.collection._


case class SplunkHecJsonLayout() extends SplunkHecJsonLayoutBase {

  import SplunkHecJsonLayout._

  @BeanProperty var maxStackTrace: Int = 500

  private val customFields = new mutable.HashMap[String, String]()

  def setCustom(customField: String): Unit = {
    customField.split("=", 2) match {
      case Array(key, value) => customFields += (key.trim -> value.trim)
      case _ => // ignoring anything else
    }
  }

  override def doLayout(event: ILoggingEvent) = {

    implicit val format = org.json4s.DefaultFormats

    val eventJson = FullEventJson(
      event.getFormattedMessage,
      event.getLevel.levelStr,
      event.getThreadName,
      event.getLoggerName,
      classOfCallerConverter.convert(event).filterEmptyConversion,
      methodOfCallerConverter.convert(event).filterEmptyConversion,
      lineOfCallerConverter.convert(event).filterEmptyConversion,
      fileOfCallerConverter.convert(event).filterEmptyConversion,
      extendedThrowableProxyConverter.convert(event).filterEmptyConversion,
      parseStackTrace(event, maxStackTrace),
      if (customFields.isEmpty) None else Some(customFields)
    )

    val baseJson = BaseJson(
      event.getTimeStamp,
      eventJson,
      if (host.isEmpty) None else Some(host),
      if (source.isEmpty) None else Some(source),
      if (sourcetype.isEmpty) None else Some(sourcetype),
      if (index.isEmpty) None else Some(index)
    )

    write(baseJson)
  }
} 
开发者ID:kdrakon,项目名称:splunk-logback-hec-appender,代码行数:58,代码来源:SplunkHecJsonLayout.scala

示例2: FakeRequest

//设置package包名称以及导入依赖的类
package io.policarp.logback.hec

import java.util.concurrent.atomic.AtomicInteger

import ch.qos.logback.classic.spi.ILoggingEvent

class FakeRequest(
    var executed: Boolean = false,
    val executions: AtomicInteger = new AtomicInteger(0),
    var lastEvent: Option[ILoggingEvent] = None
) {
  var nextIncrement: () => Unit = _
}

trait FakeHecClient extends SplunkHecClient {

  override type AbstractRequest = FakeRequest

  var fakeRequest = new FakeRequest()

  override private[hec] def prepareRequest = (events, layout) => {
    if (events.nonEmpty) {
      fakeRequest.lastEvent = Some(events.reverse.head)
      fakeRequest.nextIncrement = () => fakeRequest.executions.addAndGet(events.size)
    }
    Some(fakeRequest)
  }

  override private[hec] def executeRequest(preparedRequest: FakeRequest) = {
    preparedRequest.executed = true
    preparedRequest.nextIncrement()
  }
} 
开发者ID:kdrakon,项目名称:splunk-logback-hec-appender,代码行数:34,代码来源:FakeHecClient.scala

示例3: SplunkHecClientTest

//设置package包名称以及导入依赖的类
package io.policarp.logback.hec

import ch.qos.logback.classic.Level
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.LayoutBase
import io.policarp.logback.MockLoggingEvent
import org.scalatest.{ Matchers, WordSpec }

class SplunkHecClientTest extends WordSpec with Matchers {

  val layout = new LayoutBase[ILoggingEvent] {
    override def doLayout(event: ILoggingEvent): String = event.getMessage
  }

  "The Object" should {
    "prepare layouts in a line separated format" in {

      import SplunkHecClient.formatJsonEvents

      formatJsonEvents(Seq(), layout) shouldBe None

      val event1 = MockLoggingEvent("SomeClass", "test 1", Level.DEBUG)
      val event2 = MockLoggingEvent("SomeClass", "test 2", Level.DEBUG)
      formatJsonEvents(Seq(event1, event2), layout) shouldBe Some("test 1\n\ntest 2")
      formatJsonEvents(Seq(event1), layout) shouldBe Some("test 1")
      formatJsonEvents(Seq(event2), layout) shouldBe Some("test 2")
    }
  }

} 
开发者ID:kdrakon,项目名称:splunk-logback-hec-appender,代码行数:31,代码来源:SplunkHecClientTest.scala

示例4: CaptureLogEvents

//设置package包名称以及导入依赖的类
package mesosphere.marathon.test

import ch.qos.logback.classic.Logger
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.{ Context, AppenderBase }
import org.slf4j.LoggerFactory

object CaptureLogEvents {
  def forBlock(block: => Unit): Vector[ILoggingEvent] = {

    val capturingAppender = new CapturingAppender
    capturingAppender.appendToRootLogger()
    try block finally capturingAppender.detachFromRootLogger()
    capturingAppender.getEvents
  }

  private class CapturingAppender extends AppenderBase[ILoggingEvent] {
    setName("capture")

    private[this] var events = Vector.empty[ILoggingEvent]
    private[this] def rootLogger: Logger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME).asInstanceOf[Logger]

    def appendToRootLogger(): Unit = {
      // Waiting for Logback to be ready.
      // See https://gist.github.com/mbknor/34944ea4589a5fc6974c
      // Should actually have been fixed with http://jira.qos.ch/browse/SLF4J-167
      while (LoggerFactory.getILoggerFactory.isInstanceOf[org.slf4j.helpers.SubstituteLoggerFactory]) {
        Thread.sleep(50)
      }
      setContext(LoggerFactory.getILoggerFactory.asInstanceOf[Context])
      start()
      rootLogger.addAppender(this)
    }

    def detachFromRootLogger(): Unit = rootLogger.detachAppender(this)

    def clearEvents(): Unit = synchronized { events = Vector.empty }
    def getEvents: Vector[ILoggingEvent] = synchronized { events }

    override def append(eventObject: ILoggingEvent): Unit = synchronized { events :+= eventObject }
  }
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:43,代码来源:CaptureLogEvents.scala

示例5: SlackWebHookAppender

//设置package包名称以及导入依赖的类
package com.yukimt.logback

import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.Layout
import ch.qos.logback.core.LayoutBase
import ch.qos.logback.core.UnsynchronizedAppenderBase
import scalaj.http._
import org.json4s.DefaultFormats
import org.json4s.native.Serialization

class SlackWebHookAppender extends UnsynchronizedAppenderBase[ILoggingEvent]{
  implicit val formats = DefaultFormats

  private var channel: Option[String] = None
  private var webHookUrl: Option[String] = None
  private var username: Option[String] = None
  private var iconEmoji: Option[String] = None
  private var layout: Layout[ILoggingEvent]  = defaultLayout

  private def defaultLayout:Layout[ILoggingEvent] = new LayoutBase[ILoggingEvent]{
    def doLayout(event: ILoggingEvent) :String =
      s"-- [${event.getLevel}] - ${event.getFormattedMessage.replaceAll("\n", "\n\t")}"
  }

  override def append(evt: ILoggingEvent) = {
    val optResult = for {
      c <- channel
      w <- webHookUrl
    } yield {
      val attachment = Attachment(layout.doLayout(evt), "danger")
      val payload = Payload(c,
        username.getOrElse("Slack Logback Appender"),
        iconEmoji.getOrElse(":japanese_goblin:"),
        "Error detected!!",
        Some(Seq(attachment)))
      val res = Http(w).postForm(Seq("payload" -> Serialization.write(payload))).asString
      if(res.code == 200) Result.Success
      else Result.Failure(res.body.toString)
    }

    optResult.getOrElse(Result.Failure("channel or webHookUrl is not set")) match {
      case Result.Success => ()
      case Result.Failure(msg) =>
        val errorMessage = s"Error in Logback-Slack Web Hook Appender: $msg"
        new RuntimeException(errorMessage).printStackTrace
        addError(errorMessage)
    }

  }

  def setChannel(t: String) = { channel = Some(if(t.startsWith("#")) t else "#" + t) }
  def setWebHookUrl(w: String) = {webHookUrl = Some(w)}
  def setUsername(u: String) = {username = Some(u)}
  def setIconEmoji(i: String) = {
    val prefix = if(i.startsWith(":")) "" else ":"
    val suffix = if(i.endsWith(":")) "" else ":"
    iconEmoji = Some(prefix + i + suffix)
  }
  def setLayout(l: Layout[ILoggingEvent]) = {layout = l}
} 
开发者ID:yuki-mt,项目名称:logback-slack-webhook-appender,代码行数:61,代码来源:SlackWebhookAppender.scala

示例6: HighlightingCompositeConverter

//设置package包名称以及导入依赖的类
package at.vizu.s2n.log

import ch.qos.logback.classic.Level
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.pattern.color.ANSIConstants._
import ch.qos.logback.core.pattern.color._


class HighlightingCompositeConverter extends ForegroundCompositeConverterBase[ILoggingEvent] {
  override def getForegroundColorCode(event: ILoggingEvent): String = {
    val level: Int = event.getLevel.toInt
    level match {
      case Level.ERROR_INT => RED_FG
      case Level.WARN_INT => YELLOW_FG
      case Level.INFO_INT => BLUE_FG
      case _ => DEFAULT_FG
    }
  }


} 
开发者ID:viZu,项目名称:nasca,代码行数:22,代码来源:HighlightingCompositeConverter.scala

示例7: TestExceptionLogFilter

//设置package包名称以及导入依赖的类
package ru.finagram.test

import ch.qos.logback.classic.spi.{ ILoggingEvent, IThrowableProxy }
import ch.qos.logback.core.filter.Filter
import ch.qos.logback.core.spi.FilterReply

class TestExceptionLogFilter extends Filter[ILoggingEvent] {

  override def decide(event: ILoggingEvent): FilterReply = {
    if (isTestException(event.getThrowableProxy)) {
      FilterReply.DENY
    } else {
      FilterReply.NEUTRAL
    }
  }

  private val testExceptionName: String = classOf[TestException].getCanonicalName

  private def isTestException(proxy: IThrowableProxy): Boolean = {
    (proxy != null) && (proxy.getClassName == testExceptionName)
  }
} 
开发者ID:finagram,项目名称:finagram,代码行数:23,代码来源:TestExceptionLogFilter.scala

示例8: MemoryAppender

//设置package包名称以及导入依赖的类
package com.programmaticallyspeaking.ncd.testing

import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.UnsynchronizedAppenderBase
import ch.qos.logback.core.encoder.Encoder
import ch.qos.logback.core.status.ErrorStatus
import java.io.ByteArrayOutputStream
import java.io.IOException

import com.programmaticallyspeaking.ncd.messaging.{Observable, SerializedSubject}

object MemoryAppender {
  private[MemoryAppender] val logEventSubject = new SerializedSubject[ILoggingEvent]

  def logEvents: Observable[ILoggingEvent] = logEventSubject
}

class MemoryAppender extends UnsynchronizedAppenderBase[ILoggingEvent] {
  import MemoryAppender._
  protected var encoder: Encoder[ILoggingEvent] = _
  protected var outputStream = new ByteArrayOutputStream

  override def start(): Unit = {
    try {
      Option(encoder).foreach(_.init(outputStream))
      super.start()
    } catch {
      case e: IOException =>
        started = false
        addStatus(new ErrorStatus("Failed to initialize encoder for appender named [" + name + "].", this, e))
    }
  }

  override protected def append(event: ILoggingEvent): Unit = {
    if (!isStarted) return
    logEventSubject.onNext(event)
    try {
      event.prepareForDeferredProcessing()
      Option(encoder).foreach(_.doEncode(event))
    } catch {
      case ioe: IOException =>
        started = false
        addStatus(new ErrorStatus("IO failure in appender", this, ioe))
    }
  }

  def setEncoder(e: Encoder[ILoggingEvent]): Unit = {
    encoder = e
  }

  def getRenderedOutput = new String(outputStream.toByteArray)
} 
开发者ID:provegard,项目名称:ncdbg,代码行数:53,代码来源:MemoryAppender.scala

示例9: ColoredLevel

//设置package包名称以及导入依赖的类
package flat.logging

import ch.qos.logback.classic.Level
import ch.qos.logback.classic.pattern.ClassicConverter
import ch.qos.logback.classic.spi.ILoggingEvent

class ColoredLevel extends ClassicConverter {
  def convert(event: ILoggingEvent): String = {
    event.getLevel match {
      case Level.TRACE => s"${Console.CYAN}TRACE${Console.RESET}"
      case Level.DEBUG => s"${Console.BLUE}DEBUG${Console.RESET}"
      case Level.INFO  => s"${Console.GREEN}INFO${Console.RESET}"
      case Level.WARN  => s"${Console.YELLOW}WARN${Console.RESET}"
      case Level.ERROR => s"${Console.RED}ERROR${Console.RESET}"
    }
  }
} 
开发者ID:keithblaha,项目名称:flat,代码行数:18,代码来源:ColoredLevel.scala

示例10: append

//设置package包名称以及导入依赖的类
package core.util

import ch.qos.logback.classic.Level
import ch.qos.logback.classic.spi.ILoggingEvent
import com.getsentry.raven.logback.SentryAppender
import server.NettyServer


  override def append(iLoggingEvent: ILoggingEvent): Unit = {
    // ???? ?????? INFO ??????????
    if (!iLoggingEvent.getLevel.isGreaterOrEqual(Level.WARN)) return

    if (iLoggingEvent.getLevel == Level.WARN && iLoggingEvent.getLoggerName == classOf[NettyServer].getName) {
      iLoggingEvent.getMessage match {
        case "Server stopped" => return
        case m if m.startsWith("---------") => return
        case _ =>
      }
    }
    super.append(iLoggingEvent)
  }
} 
开发者ID:citrum,项目名称:storage-server,代码行数:23,代码来源:SentryFilteredAppender.scala

示例11: append

//设置package包名称以及导入依赖的类
package webby.commons.system.log

import ch.qos.logback.classic.Level
import ch.qos.logback.classic.spi.ILoggingEvent
import com.getsentry.raven.RavenFactory
import com.getsentry.raven.logback.SentryAppender


  override def append(iLoggingEvent: ILoggingEvent): Unit = {
    // ???? ?????? INFO ??????????
    if (!iLoggingEvent.getLevel.isGreaterOrEqual(Level.WARN)) return

    if (iLoggingEvent.getLevel == Level.WARN && iLoggingEvent.getLoggerName == "webby") {
      iLoggingEvent.getMessage match {
        case "Starting server" => return
        case m if m.startsWith("---------") => return
        case _ =>
      }
    }
    super.append(iLoggingEvent)
  }
} 
开发者ID:citrum,项目名称:webby,代码行数:23,代码来源:SentryFilteredAppender.scala

示例12: ScalyrAppender

//设置package包名称以及导入依赖的类
package io.grhodes.scalyr.logback

import ch.qos.logback.classic.Level
import ch.qos.logback.classic.spi.ILoggingEvent
import com.scalyr.api.logs.{EventAttributes, Events}

class ScalyrAppender extends AbstractScalyrAppender[ILoggingEvent] {
  override def append(event: ILoggingEvent): Unit = {
    val msg = this.layout.doLayout(event)
    val level = event.getLevel.toInt
    if (level >= Level.ERROR_INT) {
      Events.error(new EventAttributes("message", msg))
    } else if (level >= Level.WARN_INT) {
      Events.warning(new EventAttributes("message", msg))
    } else if (level >= Level.INFO_INT) {
      Events.info(new EventAttributes("message", msg))
    } else if (level >= Level.DEBUG_INT) {
      Events.fine(new EventAttributes("message", msg))
    } else if (level >= Level.TRACE_INT) {
      Events.finer(new EventAttributes("message", msg))
    } else {
      Events.finest(new EventAttributes("message", msg))
    }
  }
} 
开发者ID:grahamar,项目名称:scalyr-logback,代码行数:26,代码来源:ScalyrAppender.scala

示例13: SpuriousErrorLogFilter

//设置package包名称以及导入依赖的类
package net.mikolak.pomisos.logging

import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.filter.Filter
import ch.qos.logback.core.spi.FilterReply


class SpuriousErrorLogFilter extends Filter[ILoggingEvent] {

  val SpuriousStrings = Set("smile.",
                            "scanning through all elements without using an index for Traversal",
                            "db}} created class ",
                            "MaxDirectMemorySize JVM option is not set")

  override def decide(event: ILoggingEvent): FilterReply =
    if (SpuriousStrings.exists(event.getFormattedMessage.contains)) {
      FilterReply.DENY
    } else {
      FilterReply.NEUTRAL
    }
} 
开发者ID:mikolak-net,项目名称:pomisos,代码行数:22,代码来源:SpuriousErrorLogFilter.scala

示例14: level

//设置package包名称以及导入依赖的类
package x7c1.wheat.splicer.core.logger

import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.classic.{Level, LoggerContext}
import ch.qos.logback.core.util.ContextUtil
import ch.qos.logback.{classic, core}
import org.slf4j
import x7c1.wheat.splicer.core.logger.Tap.implicits.Provider


trait LoggerFactory {

  val context: LoggerContext =
    slf4j.LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext] tap { x =>
      val util = new ContextUtil(x)
      val add = util.addFrameworkPackage(x.getFrameworkPackages, _: String)
      (frameworkPackages :+ getClass.getPackage.getName) foreach add
    }

  val appenderFactories: Seq[Appender.Factory]

  lazy val appenders: Seq[core.Appender[ILoggingEvent]] = {
    appenderFactories.map(_ (context))
  }

  def level: Level

  def frameworkPackages: Seq[String] = Seq()

  def apply[X](klass: Class[X]): slf4j.Logger = {
    slf4j.LoggerFactory.getLogger(klass).asInstanceOf[classic.Logger].tap(
      appenders foreach _.addAppender,
      _ setLevel level,
      _ setAdditive false
    )
  }

}

object Appender {

  type Factory = LoggerContext => core.Appender[ILoggingEvent]

  type From[X] = X => Factory

  def from[X: From](x: X): Factory = {
    implicitly[From[X]] apply x
  }
} 
开发者ID:x7c1,项目名称:Wheat,代码行数:50,代码来源:LoggerFactory.scala

示例15: RollingFileSetting

//设置package包名称以及导入依赖的类
package x7c1.wheat.splicer.core.logger

import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.FileAppender
import ch.qos.logback.core.rolling.{RollingFileAppender, TimeBasedRollingPolicy}
import x7c1.wheat.splicer.core.logger.Tap.implicits.Provider

case class RollingFileSetting(
  encoderPattern: String,
  fileName: String,
  fileNamePattern: String,
  maxHistory: Int
)

object RollingFileSetting {

  implicit def createAppender: Appender.From[RollingFileSetting] = {
    setting => context =>
      val encoder = new PatternLayoutEncoder().tap(
        _ setPattern setting.encoderPattern,
        _ setContext context,
        _ start()
      )
      val policy = new TimeBasedRollingPolicy[ILoggingEvent]().tap(
        _ setFileNamePattern setting.fileNamePattern,
        _ setMaxHistory setting.maxHistory,
        _ setContext context,
        _ setParent new FileAppender[ILoggingEvent]().tap(
          _ setFile setting.fileName
        ),
        _ start()
      )
      new RollingFileAppender[ILoggingEvent]().tap(
        _ setEncoder encoder,
        _ setContext context,
        _ setRollingPolicy policy,
        _ start()
      )
  }
} 
开发者ID:x7c1,项目名称:Wheat,代码行数:42,代码来源:RollingFileSetting.scala


注:本文中的ch.qos.logback.classic.spi.ILoggingEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。