• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Logger类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Logger类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)))
  }
} 
开发者ID:TerriaJS,项目名称:magda,代码行数:51,代码来源:ApiSpec.scala


示例2: 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


示例3: 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?")
    }
  }
} 
开发者ID:Dwolla,项目名称:scala-test-utils,代码行数:42,代码来源:LoggingTest.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala JsBoolean类代码示例发布时间:2022-05-23
下一篇:
Scala ClusterSingletonProxy类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap