fails to customize an akka application log msg using logback and slf4j if Kamon is used

165 views
Skip to first unread message

colum...@gmail.com

unread,
Sep 30, 2014, 4:03:57 AM9/30/14
to kamon...@googlegroups.com
Hi all,

The application-logged msg of an akka application seems to be always directed to java.util.logging.
I want to customize the logging by using slf4j and logback.

In application.conf, I set
akka.loggers = ["akka.event.slf4j.Slf4jLogger"]

In build.sbt, I set
libraryDependencies ++= Seq(
otherjars,
"com.typesafe.akka" %% "akka-slf4j" % "2.3.3",
"ch.qos.logback" % "logback-classic" % "1.1.1",
"com.typesafe.scala-logging" %% "scala-logging" % "3.1.0"
)

I also set logback.xml as
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder>
<!-- <pattern>%logger{1} - %msg%n</pattern> -->
<pattern>[%level{10}] [%date{ISO8601}] Thread:[%thread] SourceThread:[%X{sourceThread}] AkkaSource:[%X{akkaSource}] %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="akka" level="INFO" />
<logger name="sample.kamon" level="DEBUG"/>
<root level="ALL">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>

When I run it, the application log msg is not in the expected form as
[INFO] [2014-09-30 17:51:20,609] Thread:[application-akka.actor.default-dispatcher-20] SourceThread:[application-akka.actor.default-dispatcher-19] AkkaSource:[akka://application/user/artifical/peak:generator] sample.kamon.PeakGenerator - schedule peak GenerateNumber
[DEBUG] [2014-09-30 17:51:24,408] Thread:[application-akka.actor.default-dispatcher-10] SourceThread:[] AkkaSource:[] sample.kamon.PeakGenerator - testing schedule peak!!!

but prefixed with an additional label as
[info] [INFO] [2014-09-30 17:51:20,609] Thread:[application-akka.actor.default-dispatcher-20] SourceThread:[application-akka.actor.default-dispatcher-19] AkkaSource:[akka://application/user/artifical/peak:generator] sample.kamon.PeakGenerator - schedule peak GenerateNumber
[info] [DEBUG] [2014-09-30 17:51:24,408] Thread:[application-akka.actor.default-dispatcher-10] SourceThread:[] AkkaSource:[] sample.kamon.PeakGenerator - testing schedule peak!!!

The label [info] seems to be coming from java.util.Logging and does not reflect the actual severity of the application log msg. How to remove it? If Kamon is not used, this problem won't happen.

Thanks again.

colum...@gmail.com

unread,
Oct 1, 2014, 4:12:00 AM10/1/14
to kamon...@googlegroups.com, colum...@gmail.com
Just found it's due to the sample akka application, not related to kamon. This problem disappears when I use kamon on my own project.

Diego Parra

unread,
Oct 1, 2014, 8:29:51 AM10/1/14
to kamon...@googlegroups.com

Thanks for sharing.

Cheers Diego.

--
You received this message because you are subscribed to the Google Groups "kamon-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kamon-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

colum...@gmail.com

unread,
Oct 1, 2014, 9:20:43 AM10/1/14
to kamon...@googlegroups.com
Just found the real cause of the problem. It's sbt forking jvm. The application should be started with the aspectj weaver, then it should be run on a forked jvm from sbt, then
http://www.scala-sbt.org/release/docs/Forking.html
If I configure the logback.xml to a file handler, the content of the log file will be ok. But I have to configure it to a console handler. The only solution is probably working on outputStrategy of sbt.
Reply all
Reply to author
Forward
0 new messages