Akka SLF4J logback configuration and usage

前端 未结 4 1675
-上瘾入骨i
-上瘾入骨i 2020-12-08 01:08

I have done the following steps to try and configure logging for my akka application:

  • created an application.conf file and placed it in src/main/resources.

4条回答
  •  感情败类
    2020-12-08 01:40

    With this arrangement I can use an akka.event.Logging, no need to specify SLF4J instance.

    (tested 13 Dec 2013)

    I get console logging and logging to a file. To prove this is not built-in logger I changed to include %X{akkaTimestamp} as explained here:

    http://doc.akka.io/docs/akka/snapshot/scala/logging.html
    

    build.sbt

    library dependencies: (Akka version 2.2.3)
    
    ...
    "com.typesafe.akka" %% "akka-slf4j" % "2.2.3"
    "ch.qos.logback" % "logback-classic" % "1.0.9"
    ...
    

    src/main/resources/application.conf

    akka {
      loggers = ["akka.event.slf4j.Slf4jLogger"]
      loglevel = "INFO"
    }
    

    src/main/resources/logback.xml

    
    
    
        
            System.out
            
                %X{akkaTimestamp} %-5level[%thread] %logger{0} - %msg%n
            
        
    
        
            log/akka.log
            false
            
                %date{yyyy-MM-dd} %X{akkaTimestamp} %-5level[%thread] %logger{1} - %msg%n
            
        
    
        
    
        
            
            
        
    
    
    

    This arrangement works when I use an ActorLogging mixin and also create a Logging directly:

    import akka.event.Logging
    
    val log = Logging(context.system, classOf[NameOfYourActor])
    
    log.info("good luck!")
    

提交回复
热议问题