本文整理汇总了Scala中ch.qos.logback.classic.Level类的典型用法代码示例。如果您正苦于以下问题:Scala Level类的具体用法?Scala Level怎么用?Scala Level使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Level类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ApiSpec
//设置package包名称以及导入依赖的类
package au.csiro.data61.magda.registry
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.testkit.ScalatestRouteTest
import akka.testkit.TestProbe
import ch.qos.logback.classic.{Level, Logger}
import org.flywaydb.core.Flyway
import org.scalatest.Matchers
import org.scalatest.fixture.FunSpec
import org.slf4j.LoggerFactory
import scala.concurrent.duration._
import scalikejdbc._
abstract class ApiSpec extends FunSpec with ScalatestRouteTest with Matchers with Protocols with SprayJsonSupport {
case class FixtureParam(api: Api, webHookActorProbe: TestProbe)
val databaseUrl = Option(System.getenv("npm_package_config_databaseUrl")).getOrElse("jdbc:postgresql://localhost:5432/postgres")
// Stop Flyway from producing so much spam that Travis terminates the process.
LoggerFactory.getLogger("org.flywaydb").asInstanceOf[Logger].setLevel(Level.WARN)
val flyway = new Flyway()
flyway.setDataSource(databaseUrl, "postgres", "")
flyway.setSchemas("test")
flyway.setLocations("classpath:/sql")
override def testConfigSource =
s"""
|db.default.url = "${databaseUrl}?currentSchema=test"
|authorization.skip = true
|akka.loglevel = INFO
""".stripMargin
override def withFixture(test: OneArgTest) = {
val webHookActorProbe = TestProbe()
val api = new Api(webHookActorProbe.ref, testConfig, system, executor, materializer)
webHookActorProbe.expectMsg(1 millis, WebHookActor.Process)
DB localTx { implicit session =>
sql"DROP SCHEMA IF EXISTS test CASCADE".update.apply()
sql"CREATE SCHEMA test".update.apply()
}
flyway.migrate()
super.withFixture(test.toNoArgTest(FixtureParam(api, webHookActorProbe)))
}
}
示例2: 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")
}
}
}
示例3: LogbackLoggerSetter
//设置package包名称以及导入依赖的类
package com.innoave.soda.logging
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.{Logger => LbLogger}
import ch.qos.logback.classic.turbo.TurboFilter
trait LogbackHelper {
implicit class LogbackLoggerSetter(logger: Logger) {
val lbl = logger.delegate.asInstanceOf[LbLogger]
def setLevel(level: Level): Unit =
lbl.setLevel(level)
def addTurboFilter(newFilter: TurboFilter): Unit = {
lbl.getLoggerContext.addTurboFilter(newFilter)
}
}
}
示例4: 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
}
}
}
示例5: TestData
//设置package包名称以及导入依赖的类
package com.malliina.logstreams
import ch.qos.logback.classic.Level
import com.malliina.logbackrx.LogEvent
import com.malliina.logstreams.models.{AppLogEvent, AppName, LogSource}
object TestData {
// Dev purposes
def dummyEvent(msg: String) = LogEvent(
System.currentTimeMillis(),
"now",
msg,
getClass.getName.stripSuffix("$"),
"this thread",
Level.INFO,
None)
def failEvent(msg: String) = LogEvent(
System.currentTimeMillis(),
"now!",
msg,
getClass.getName.stripSuffix("$"),
Thread.currentThread().getName,
Level.ERROR,
Option(new Exception("boom").getStackTraceString)
)
def testEvent(e: LogEvent) = AppLogEvent(LogSource(AppName("test"), "localhost"), e)
}
示例6: 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}"
}
}
}
示例7: 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)
}
}
示例8: 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)
}
}
示例9: haveBeenLoggedAtLevel
//设置package包名称以及导入依赖的类
package com.dwolla.testutils.logging
import ch.qos.logback.classic.{Level, Logger}
import org.slf4j.helpers.SubstituteLogger
import org.slf4j.{Logger => SLF4JLogger, LoggerFactory}
import org.specs2.matcher.{Expectable, Matcher}
import org.specs2.mutable.SpecificationLike
import org.specs2.text.Sentences._
trait LoggingTest extends SpecificationLike {
protected val logAppenderName = "inMemory"
private val appender = findInMemoryAppender(logAppenderName)
def haveBeenLoggedAtLevel(logLevel: Level): Matcher[String] = new Matcher[String] {
def apply[S <: String](s: Expectable[S]) = {
val containsAtLevel = appender.containsAtLevel(s.value, logLevel)
val errorMessage =
if (containsAtLevel)
"The expected logging occurred"
else if (appender.contains(s.value))
s"“${s.value}” was logged at the wrong level"
else
s"“${s.value}” was never logged"
result(containsAtLevel, negateSentence(errorMessage), errorMessage, s)
}
}
def resetCapturedLogs(): Unit = appender.reset()
def dumpCapturedLogsToSysOut(): Unit = appender.dumpLogs()
private def findInMemoryAppender(s: String): InMemoryAppender = {
LoggerFactory.getLogger(SLF4JLogger.ROOT_LOGGER_NAME) match {
case logger: Logger => logger.getAppender(s) match {
case inMemoryAppender: InMemoryAppender => inMemoryAppender
case _ => throw new IllegalStateException(s"Is the InMemoryAppender registered with logback in its configuration file with the name $s?")
}
case sub: SubstituteLogger => throw new IllegalStateException("SLF4J is probably still initializing. Is LoggingTest part of the outermost class wrapping your tests?")
case _ => throw new IllegalStateException("Are you using LogBack logging?")
}
}
}
示例10: 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))
}
}
}
示例11: 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
}
}
示例12: Logging
//设置package包名称以及导入依赖的类
package x7c1.wheat.splicer.core.logger
import ch.qos.logback.classic.Level
import sbt.ProcessLogger
trait Logging {
lazy val logger: ProcessLogger = LoggerWrapper(Logging(getClass))
}
object Logging extends LoggerFactory {
override lazy val level = Level.DEBUG
override def frameworkPackages = Seq(
classOf[LoggerWrapper].getPackage.getName
)
override lazy val appenderFactories = Seq(
Appender from RollingFileSetting(
encoderPattern = """%d{yyyy-MM-dd'T'HH:mm:ss'Z'} [%thread] %level %logger{0} - %msg \(%file:%line\)%n""",
fileName = "logs/app.log",
fileNamePattern = "logs/app.%d{yyyy-MM-dd}.log",
maxHistory = 7
)
)
}