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

Scala LogManager类代码示例

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

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



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

示例1: LoggerFactoryConfigurator

//设置package包名称以及导入依赖的类
package com.flipkart.connekt.commons.factories

import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.LoggerContext
import org.apache.logging.log4j.core.config.xml.XmlConfiguration
import org.apache.logging.log4j.core.config.{ConfigurationSource, Configurator}

object LoggerFactoryConfigurator {

  def configureLog4j2(log4j2ConfigFile: String, async: Boolean = true) = {
    if(async)
      System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")

    val context: LoggerContext = LogManager.getContext(false).asInstanceOf[LoggerContext]
    val configStream = getClass.getClassLoader.getResourceAsStream(log4j2ConfigFile)
    val config = new XmlConfiguration(new ConfigurationSource(configStream))
    context.start(config)
  }

  def shutdownLog4j2() = {
    val context: LoggerContext = LogManager.getContext(false).asInstanceOf[LoggerContext]
    Configurator.shutdown(context)
  }
} 
开发者ID:ayush03agarwal,项目名称:connekt,代码行数:25,代码来源:LoggerFactoryConfigurator.scala


示例2: ConnektLogger

//设置package包名称以及导入依赖的类
package com.flipkart.connekt.commons.factories

import org.apache.logging.log4j.LogManager

object ConnektLogger {

  def init(logConfFilePath: String) = LoggerFactoryConfigurator.configureLog4j2(logConfFilePath)

  def shutdown() = LoggerFactoryConfigurator.shutdownLog4j2()

  def apply(logFile: String) = {
    LogManager.getLogger(logFile)
  }
}

object LogFile {
  final val ACCESS = "ACCESS"
  final val FACTORY = "FACTORY"
  final val SERVICE = "SERVICE"
  final val DAO = "DAO"
  final val WORKERS = "WORKERS"
  final val CLIENTS = "CLIENTS"
  final val PROCESSORS = "PROCESSORS"
  final val CALLBACKS = "CALLBACKS"
} 
开发者ID:ayush03agarwal,项目名称:connekt,代码行数:26,代码来源:ConnektLogger.scala


示例3: LoggerFactoryConfiguratorTest

//设置package包名称以及导入依赖的类
package com.flipkart.connekt.commons.tests.factories

import com.flipkart.connekt.commons.tests.ConnektUTSpec
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.LoggerContext
import org.apache.logging.log4j.core.config.xml.XmlConfiguration
import org.apache.logging.log4j.core.config.{ConfigurationSource, Configurator}
import org.slf4j.{Logger, LoggerFactory}

class LoggerFactoryConfiguratorTest extends ConnektUTSpec {

  "LoggerFactory configuration" should "complete without exceptions" in {
    ConnektLogger.init()
  }
  
  "Logging at different levels" should "be re-directed to STDOUT" in {
    implicit val logFile = "connekt.core"
    ConnektLogger(logFile).trace("Sample [trace] message" + System.currentTimeMillis())
    ConnektLogger(logFile).debug("Sample [debug] message" + System.currentTimeMillis())
    ConnektLogger(logFile).info("Sample [info] message" + System.currentTimeMillis())
    ConnektLogger(logFile).warn("Sample [warn] message" + System.currentTimeMillis())
    ConnektLogger(logFile).error("Sample [error] message" + System.currentTimeMillis())
  }

  "LoggerFactory terminate" should "stop without exceptions" in {
    ConnektLogger.stop()
  }
}


object ConnektLogger {

  def init() = {
    System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")

    val context: LoggerContext = LogManager.getContext(false).asInstanceOf[LoggerContext]
    val config = new XmlConfiguration(new ConfigurationSource(ClassLoader.getSystemResourceAsStream("log4j2-test.xml")))
    context.start(config)
  }

  def stop() = {
    val context: LoggerContext = LogManager.getContext.asInstanceOf[LoggerContext]
    Configurator.shutdown(context)
  }

  def apply(implicit fileName: String): Logger = LoggerFactory.getLogger(fileName)

} 
开发者ID:ayush03agarwal,项目名称:connekt,代码行数:49,代码来源:LoggerFactoryConfiguratorTest.scala


示例4: weightAndSort

//设置package包名称以及导入依赖的类
package ru.ispras.atr.rank

import org.apache.logging.log4j.LogManager
import ru.ispras.atr.datamodel.{DSDataset, Identifiable, TermCandidate}
import ru.ispras.atr.features.FeatureConfig


trait TermCandidatesWeighter extends Identifiable {
  val log = LogManager.getLogger(getClass)

  def weightAndSort(candidates: Seq[TermCandidate], dataset: DSDataset): Iterable[(String, Double)]
}

trait TermCandidatesWeighterConfig {
  def build(): TermCandidatesWeighter
}

object TermCandidatesWeighterConfig {
  val subclasses = List(
    classOf[OneFeatureTCWeighterConfig],
    classOf[SparkOneFeatureTCWeighterConfig],
    classOf[VotingTCWeighterConfig]) ++
    PUTCWeighterConfig.subclasses ++
    FeatureConfig.subclasses
} 
开发者ID:ispras,项目名称:atr4s,代码行数:26,代码来源:TermCandidatesWeighter.scala


示例5: build

//设置package包名称以及导入依赖的类
package ru.ispras.atr.features

import org.apache.logging.log4j.LogManager
import ru.ispras.atr.datamodel.{DSDataset, Identifiable, TermCandidate}
import ru.ispras.atr.features.contexts.{DomainCoherence, PostRankDC, PMI}
import ru.ispras.atr.features.keyrel.KeyPhraseRelatedness
import ru.ispras.atr.features.meta.{FilterFeature, LinearCombinationFeature}
import ru.ispras.atr.features.occurrences._
import ru.ispras.atr.features.refcorpus.{DomainPertinence, ReferenceCorpusConfig, Relevance, Weirdness}
import ru.ispras.atr.features.tm.NovelTopicModel
import ru.ispras.atr.features.wiki.{LinkProbability, WikiPresenceFeature}


trait FeatureConfig extends Identifiable {
  val log = LogManager.getLogger(getClass)

  def build(candidates: Seq[TermCandidate], dataset: DSDataset): FeatureComputer
}

object FeatureConfig {
  val subclasses = List(
    classOf[FeatureConfig],
    classOf[Basic],
    classOf[ComboBasic],
    classOf[CValue],
    classOf[DocFrequency],
    classOf[DomainCoherence], classOf[PMI],
    classOf[PostRankDC],
    classOf[LinearCombinationFeature],
    classOf[LinkProbability],

    classOf[ReferenceCorpusConfig],
    classOf[Relevance],
    classOf[Weirdness],
    classOf[DomainPertinence],

    classOf[TermFrequency],
    classOf[AvgTermFrequency],
    classOf[TotalTFIDF],
    classOf[ResidualIDF],

    classOf[NovelTopicModel],
    classOf[WordsCount],
    classOf[FilterFeature],
    classOf[WikiPresenceFeature],
    classOf[ExpectedTermsPresence],
    classOf[RandomFeature],
    classOf[CachingFeature]
  ) ++ KeyPhraseRelatedness.subclasses
} 
开发者ID:ispras,项目名称:atr4s,代码行数:51,代码来源:FeatureConfig.scala


示例6: Log4J2LoggerConfigurator

//设置package包名称以及导入依赖的类
import java.io.File
import java.net.URL

import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.LoggerContext
import org.apache.logging.log4j.core.config.Configurator
import play.api.{Environment, LoggerConfigurator, Mode}

class Log4J2LoggerConfigurator extends LoggerConfigurator {

  override def init(rootPath: File, mode: Mode.Mode): Unit = {
    val properties = Map("application.home" -> rootPath.getAbsolutePath)
    val resourceName = "log4j2.xml"
    val resourceUrl = Option(this.getClass.getClassLoader.getResource(resourceName))
    configure(properties, resourceUrl)
  }

  override def shutdown(): Unit = {
    val context = LogManager.getContext().asInstanceOf[LoggerContext]
    Configurator.shutdown(context)
  }

  override def configure(env: Environment): Unit = {
    val properties = Map("application.home" -> env.rootPath.getAbsolutePath)
    val resourceUrl = env.resource("log4j2.xml")
    configure(properties, resourceUrl)
  }

  override def configure(properties: Map[String, String], config: Option[URL]): Unit = {
    val context = LogManager.getContext(false).asInstanceOf[LoggerContext]
    context.setConfigLocation(config.get.toURI)
  }
} 
开发者ID:playframework,项目名称:play-scala-log4j2-example,代码行数:34,代码来源:Log4J2LoggerConfigurator.scala


示例7: FileIO

//设置package包名称以及导入依赖的类
package de.htwg.se.dog2.util.FileIOXmlImpl

import java.io.{ BufferedWriter, File, FileWriter }

import de.htwg.se.dog2.model.Game
import de.htwg.se.dog2.util.TFileIO
import org.apache.logging.log4j.{ LogManager, Logger }


class FileIO extends TFileIO {

  var logger: Logger = LogManager.getLogger(FileIO.this)

  def save(game: Game): Unit = {
    logger.debug("Saving game data in XML...")
    val save = this.toXml(game: Game)
    val file = new File("savedGame.xml")
    val bufferedWriter = new BufferedWriter(new FileWriter(file))
    bufferedWriter.write(fromXml(save))
    bufferedWriter.close()
    logger.debug("Finished saving game data.")
  }

  def toXml(game: Game): scala.xml.Node = {
    <game>
      <figureList>{ game.figureList }</figureList>
      <playerList>{ game.playerList }</playerList>
      <fieldList>{ game.fieldList }</fieldList>
      <cardList>{ game.cardList }</cardList>
      <cardDecks>{ game.cardDeck }</cardDecks>
      <playedCards>{ game.playedCards }</playedCards>
      <currentPlayer>{ game.currentPlayer }</currentPlayer>
      <currentFigure>{ game.currentFigure }</currentFigure>
      <currentFigNr>{ game.currentFigNr }</currentFigNr>
      <deckSize>{ game.deckSize }</deckSize>
    </game>
  }

  def fromXml(node: scala.xml.Node): String = {
    node.text
  }

} 
开发者ID:MarkusBuechler,项目名称:SE2017SS-DOG,代码行数:44,代码来源:FileIO.scala


示例8: DogTui

//设置package包名称以及导入依赖的类
package de.htwg.se.dog2.view

import com.google.inject.Inject
import de.htwg.se.dog2.controller.gameController
import org.apache.logging.log4j.{ LogManager, Logger }

import scala.swing.Reactor


// $COVERAGE-OFF$Disabling highlighting by default until scala swing integration test franework is found.
class DogTui @Inject() (var gameController: gameController) extends Reactor {

  var logger: Logger = LogManager.getLogger(DogTui.this)

  val info = "Enter command: q-Quit; m - TestCard ; g - init cards/field ; s - setup player ; n-New Game ; i-Information\n"
  var continue = true
  def update(): Unit = printTui()

  def printTui(): Unit = {
    logger.info(info)
    gameController.showGameStatus()

  }

  printTui()

  def processInputLine(input: String): Boolean = {
    continue = true
    input match {
      case "q" =>
        print("q wurde gedrückt !\nSpiel wird bald verlassen\n")
        gameController.quitGame()
      case "n" =>
        print("n wurde gedrückt !\nSpiel wird gestartet\n")
        print("\nWelche Karte möchtest du spielen?\n")
        gameController.showGameStatus()
        continue = true
      case "y" =>
        print("Welche Karte soll mit welcher Figur gespielt werden?\n")
        val input = scala.io.StdIn.readLine()
        val tokens = input.split(" ")
        if (tokens.length != 1) {
          print("Falsche Eingabe!\n")
          print(info)
        } else {
          gameController.playerAction(tokens(0).toInt)
          printTui()
        }
      case "g" =>
        gameController.changeCurrentFigureNr()
        printTui()
      case _ => print("False Eingabe\n"); print(info)
    }
    continue
  }

}
// $COVERAGE-ON$ 
开发者ID:MarkusBuechler,项目名称:SE2017SS-DOG,代码行数:59,代码来源:DogTui.scala


示例9: Configuration

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

import java.io.File

import com.typesafe.config.{ConfigFactory, Config}
import org.apache.logging.log4j.LogManager

class Configuration() {
  private val log = LogManager.getLogger(classOf[Configuration])

  val config: Config = {
    val configDefaults = ConfigFactory.load(this.getClass.getClassLoader, "application.conf")

    scala.sys.props.get("production.conf") match {
      case Some(filename) =>
        val configFile = new File(filename)
        assert(configFile.canRead)
        log.info(s"loading $configFile as config")
        ConfigFactory.parseFile(configFile).withFallback(configDefaults)
      case None =>
        log.info("no config override found, use default as config")
        configDefaults
    }
  }

  object ExampleRemoteServer {
    val url: String = config.getString("ExampleRemoteServer.url")
  }

} 
开发者ID:mwang633,项目名称:example-service,代码行数:31,代码来源:Configuration.scala


示例10: DataAccess

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

import org.apache.logging.log4j.LogManager

import scala.concurrent.{ExecutionContextExecutor, Future}

class DataAccess(conf : Configuration, implicit val ec : ExecutionContextExecutor) {
  import Schema._
  import slick.driver.PostgresDriver.api._

  lazy val db = Database.forConfig("database", conf.config)
  val log = LogManager.getLogger(classOf[DataAccess])

  def findData(user_id : String) : Future[Option[ExampleDataRow]] = {
    log.debug(s"findData $user_id")
    db.run(exampleTable.filter(_.userId === user_id).result.headOption)
  }

  def updateData(row : ExampleDataRow) : Future[ExampleDataRow] = {
    log.debug(s"updateData $row")
    db.run(exampleTable.insertOrUpdate(row)).map(_ => row)
  }
} 
开发者ID:mwang633,项目名称:example-service,代码行数:24,代码来源:DataAccess.scala


示例11: ExampleResponse

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

import akka.actor.ActorRefFactory
import org.apache.logging.log4j.LogManager
import spray.client.pipelining._
import spray.http.{FormData, HttpRequest, HttpResponse}
import spray.httpx.SprayJsonSupport._
import spray.json.DefaultJsonProtocol

import scala.concurrent.Future


case class ExampleResponse(id : String, name : String)

class ExampleClient(config : Configuration, implicit val system: ActorRefFactory) {
  private object JsonProtocol extends DefaultJsonProtocol {
    implicit val exampleResponseFormat = jsonFormat2(ExampleResponse)
  }

  import JsonProtocol._
  import system.dispatcher

  private val log = LogManager.getLogger(this.getClass)

  private val logRequest: HttpRequest => HttpRequest = { r =>
    log.debug(r.toString)
    log.trace(r.entity.data.asString)
    r
  }

  private val logResponse: HttpResponse => HttpResponse = { r =>
    log.debug(r.toString)
    log.trace(r.entity.data.asString)
    r
  }

  private val jsonQuery = addHeader("Accept", "application/json") ~> logRequest ~> sendReceive ~> logResponse

  def requestFuture(id : String) : Future[ExampleResponse] = {
    val pipeline = jsonQuery ~> unmarshal[ExampleResponse]

    pipeline {
      Get(s"${config.ExampleRemoteServer.url}/getUser", FormData(Seq("id" -> id)))
    }
  }
} 
开发者ID:mwang633,项目名称:example-service,代码行数:47,代码来源:ExampleClient.scala


示例12: tailLog

//设置package包名称以及导入依赖的类
package teleporter.integration.component.log

import akka.NotUsed
import akka.stream.Materializer
import akka.stream.scaladsl.Source
import akka.util.ByteString
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.LoggerContext
import org.apache.logging.log4j.core.appender.RollingFileAppender
import teleporter.integration.component.file.FileCmd

import scala.collection.JavaConverters._


trait Logs {
  private val logFileAppender: RollingFileAppender = {
    val loggerContext = LogManager.getContext(true).asInstanceOf[LoggerContext]
    loggerContext.getConfiguration.getAppenders.asScala.collect {
      case (_, v: RollingFileAppender) ? v
    }.head
  }

  def tailLog()(implicit mater: Materializer): Source[ByteString, NotUsed] = {
    FileCmd.exec(s"tail ${logFileAppender.getFileName}")
  }
}

object Logs extends Logs 
开发者ID:huanwuji,项目名称:teleporter,代码行数:29,代码来源:Logs.scala


示例13: FileTailerPublisherTest

//设置package包名称以及导入依赖的类
package teleporter.integration.component.file

import java.nio.file.Paths
import java.util.concurrent.atomic.AtomicLong
import java.util.concurrent.locks.LockSupport

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Framing, Sink, Source}
import akka.util.ByteString
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.LoggerContext
import org.apache.logging.log4j.core.appender.RollingFileAppender
import org.apache.logging.log4j.scala.Logging
import org.scalatest.FunSuite

import scala.collection.JavaConverters._
import scala.concurrent.duration._


class FileTailerPublisherTest extends FunSuite with Logging {
  implicit val system = ActorSystem()
  implicit val mater = ActorMaterializer()
  test("tail publish") {
    val loggerContext = LogManager.getContext(true).asInstanceOf[LoggerContext]
    val path = loggerContext.getConfiguration.getAppenders.asScala.collect {
      case (_, v: RollingFileAppender) ? Paths.get(v.getFileName)
    }.head
    println(path.toFile.getCanonicalPath)
    FileTailer.source(path)
      .via(Framing.delimiter(ByteString(System.lineSeparator()), 1024 * 5))
      .runForeach(bs ? println(bs.utf8String))
    val counter = new AtomicLong()
    Source.tick(2.seconds, 2.seconds, "ttttet").map(x ? logger.info(counter.incrementAndGet().toString)).to(Sink.ignore).run()
    logger.info("====================")
    LockSupport.park()
  }
} 
开发者ID:huanwuji,项目名称:teleporter,代码行数:39,代码来源:FileTailerPublisherTest.scala


示例14: Log4J2LogLevelConverter

//设置package包名称以及导入依赖的类
package logoon.adapters.log4j2

import logoon.{ LogLevel, LoggerAdapter, LogLevelConfig }
import org.apache.logging.log4j
import org.apache.logging.log4j.core.LoggerContext
import org.apache.logging.log4j.{ LogManager, ThreadContext }

object Log4J2LogLevelConverter {
  def toLog4J(level: LogLevel): log4j.Level = level match {
    case LogLevel.OFF   => log4j.Level.OFF
    case LogLevel.FATAL => log4j.Level.FATAL
    case LogLevel.ERROR => log4j.Level.ERROR
    case LogLevel.WARN  => log4j.Level.WARN
    case LogLevel.INFO  => log4j.Level.INFO
    case LogLevel.DEBUG => log4j.Level.DEBUG
    case LogLevel.TRACE => log4j.Level.TRACE
    case LogLevel.ALL   => log4j.Level.ALL
  }
  def fromLog4J(level: log4j.Level): LogLevel = level match {
    case log4j.Level.OFF   => LogLevel.OFF
    case log4j.Level.ERROR => LogLevel.ERROR
    case log4j.Level.WARN  => LogLevel.WARN
    case log4j.Level.INFO  => LogLevel.INFO
    case log4j.Level.DEBUG => LogLevel.DEBUG
    case log4j.Level.TRACE => LogLevel.TRACE
    case log4j.Level.ALL   => LogLevel.ALL
  }
}

object Log4J2LogLevelConfig extends LogLevelConfig {
  override def logLevel(name: String): LogLevel =
    Log4J2LogLevelConverter.fromLog4J(LogManager.getLogger(name).getLevel)
  override def setLogLevel(name: String, level: LogLevel): Unit = {
    val log4JLevel   = Log4J2LogLevelConverter.toLog4J(level)
    val log4jContext = LogManager.getContext(false).asInstanceOf[LoggerContext]
    log4jContext.getConfiguration.getLoggerConfig(name).setLevel(log4JLevel)
    log4jContext.updateLoggers()
  }
}

object Log4J2LoggerAdapter extends LoggerAdapter {

  private def withMDC(name: String, context: Map[String, String])(f: log4j.Logger => Unit): Unit = {
    import scala.collection.JavaConverters._
    val existingContext = ThreadContext.getImmutableContext
    ThreadContext.clearMap()
    ThreadContext.putAll(context.asJava)
    f(LogManager.getLogger(name))
    ThreadContext.clearMap()
    ThreadContext.putAll(existingContext)
  }

  override def log(name: String, level: LogLevel, message: =>String, context: Map[String, String]): Unit =
    withMDC(name, context)(_.log(Log4J2LogLevelConverter.toLog4J(level), message))

  override def log(name: String, level: LogLevel, message: => String, throwable: => Throwable, context: Map[String, String]): Unit =
    withMDC(name, context)(_.log(Log4J2LogLevelConverter.toLog4J(level), message, throwable))
} 
开发者ID:btlines,项目名称:logoon,代码行数:59,代码来源:Log4J2Adapter.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala WeightInit类代码示例发布时间:2022-05-23
下一篇:
Scala Callback类代码示例发布时间: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