Merge branch 'master' of github.com:jboner/akka
This commit is contained in:
commit
b4c09c6f7b
6 changed files with 49 additions and 17 deletions
|
|
@ -142,7 +142,7 @@ akka.dev.conf:
|
||||||
::
|
::
|
||||||
|
|
||||||
akka {
|
akka {
|
||||||
event-handler-level = "DEBUG"
|
loglevel = "DEBUG"
|
||||||
}
|
}
|
||||||
|
|
||||||
The mode option works in the same way when using configuration files in ``AKKA_HOME/config/`` directory.
|
The mode option works in the same way when using configuration files in ``AKKA_HOME/config/`` directory.
|
||||||
|
|
@ -162,7 +162,7 @@ akka.dev.conf:
|
||||||
include "akka.conf"
|
include "akka.conf"
|
||||||
|
|
||||||
akka {
|
akka {
|
||||||
event-handler-level = "DEBUG"
|
loglevel = "DEBUG"
|
||||||
}
|
}
|
||||||
|
|
||||||
.. _-Dakka.output.config.source:
|
.. _-Dakka.output.config.source:
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ You can configure which event handlers should be registered at boot time. That i
|
||||||
akka {
|
akka {
|
||||||
# event handlers to register at boot time (EventHandler$DefaultListener logs to STDOUT)
|
# event handlers to register at boot time (EventHandler$DefaultListener logs to STDOUT)
|
||||||
event-handlers = ["akka.event.EventHandler$DefaultListener"]
|
event-handlers = ["akka.event.EventHandler$DefaultListener"]
|
||||||
event-handler-level = "DEBUG" # Options: ERROR, WARNING, INFO, DEBUG
|
loglevel = "DEBUG" # Options: ERROR, WARNING, INFO, DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
The default one logs to STDOUT and is registered by default. It is not intended to be used for production. There is also an :ref:`slf4j` event handler available in the 'akka-slf4j' module.
|
The default one logs to STDOUT and is registered by default. It is not intended to be used for production. There is also an :ref:`slf4j` event handler available in the 'akka-slf4j' module.
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ SLF4J
|
||||||
=====
|
=====
|
||||||
|
|
||||||
This module is available in the 'akka-slf4j.jar'. It has one single dependency; the slf4j-api jar. In runtime you
|
This module is available in the 'akka-slf4j.jar'. It has one single dependency; the slf4j-api jar. In runtime you
|
||||||
also need a SLF4J backend, we recommend:
|
also need a SLF4J backend, we recommend `Logback <http://logback.qos.ch/>`_:
|
||||||
|
|
||||||
.. code-block:: scala
|
.. code-block:: scala
|
||||||
|
|
||||||
lazy val logback = "ch.qos.logback" % "logback-classic" % "0.9.28" % "runtime"
|
lazy val logback = "ch.qos.logback" % "logback-classic" % "1.0.0" % "runtime"
|
||||||
|
|
||||||
|
|
||||||
Event Handler
|
Event Handler
|
||||||
|
|
@ -20,8 +20,22 @@ This module includes a SLF4J Event Handler that works with Akka's standard Event
|
||||||
|
|
||||||
akka {
|
akka {
|
||||||
event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
|
event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
|
||||||
event-handler-level = "DEBUG"
|
loglevel = "DEBUG"
|
||||||
}
|
}
|
||||||
|
|
||||||
Read more about how to use the :ref:`event-handler`.
|
Read more about how to use the :ref:`event-handler`.
|
||||||
|
|
||||||
|
Logging thread in MDC
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
Since the logging is done asynchronously the thread in which the logging was performed is captured in
|
||||||
|
Mapped Diagnostic Context (MDC) with attribute name ``sourceThread``.
|
||||||
|
With Logback the thread name is available with ``%X{sourceThread}`` specifier within the pattern layout configuration::
|
||||||
|
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<layout>
|
||||||
|
<pattern>%date{ISO8601} %-5level %logger{36} %X{sourceThread} - %msg%n</pattern>
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -750,7 +750,7 @@ All these messages are logged at ``DEBUG`` level. To summarize, you can enable
|
||||||
full logging of actor activities using this configuration fragment::
|
full logging of actor activities using this configuration fragment::
|
||||||
|
|
||||||
akka {
|
akka {
|
||||||
event-handler-level = "DEBUG"
|
loglevel = "DEBUG"
|
||||||
actor {
|
actor {
|
||||||
debug {
|
debug {
|
||||||
receive = "true"
|
receive = "true"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
package akka.event.slf4j
|
package akka.event.slf4j
|
||||||
|
|
||||||
import org.slf4j.{ Logger ⇒ SLFLogger, LoggerFactory ⇒ SLFLoggerFactory }
|
import org.slf4j.{ Logger ⇒ SLFLogger, LoggerFactory ⇒ SLFLoggerFactory }
|
||||||
|
import org.slf4j.MDC
|
||||||
import akka.event.Logging._
|
import akka.event.Logging._
|
||||||
import akka.actor._
|
import akka.actor._
|
||||||
|
|
||||||
|
|
@ -27,31 +27,49 @@ object Logger {
|
||||||
/**
|
/**
|
||||||
* SLF4J Event Handler.
|
* SLF4J Event Handler.
|
||||||
*
|
*
|
||||||
|
* The thread in which the logging was performed is captured in
|
||||||
|
* Mapped Diagnostic Context (MDC) with attribute name "sourceThread".
|
||||||
|
*
|
||||||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||||
*/
|
*/
|
||||||
class Slf4jEventHandler extends Actor with SLF4JLogging {
|
class Slf4jEventHandler extends Actor with SLF4JLogging {
|
||||||
|
|
||||||
|
val mdcThreadAttributeName = "sourceThread"
|
||||||
|
|
||||||
def receive = {
|
def receive = {
|
||||||
case event @ Error(cause, logSource, message) ⇒
|
case event @ Error(cause, logSource, message) ⇒
|
||||||
Logger(logSource).error("[{}] [{}] [{}]",
|
withMdc(mdcThreadAttributeName, event.thread.getName) {
|
||||||
Array[AnyRef](event.thread.getName, message.asInstanceOf[AnyRef], stackTraceFor(cause)))
|
Logger(logSource).error(message.toString, cause)
|
||||||
|
}
|
||||||
|
|
||||||
case event @ Warning(logSource, message) ⇒
|
case event @ Warning(logSource, message) ⇒
|
||||||
Logger(logSource).warn("[{}] [{}]",
|
withMdc(mdcThreadAttributeName, event.thread.getName) {
|
||||||
event.thread.getName, message.asInstanceOf[AnyRef])
|
Logger(logSource).warn("{}", message.asInstanceOf[AnyRef])
|
||||||
|
}
|
||||||
|
|
||||||
case event @ Info(logSource, message) ⇒
|
case event @ Info(logSource, message) ⇒
|
||||||
Logger(logSource).info("[{}] [{}]",
|
withMdc(mdcThreadAttributeName, event.thread.getName) {
|
||||||
event.thread.getName, message.asInstanceOf[AnyRef])
|
Logger(logSource).info("{}", message.asInstanceOf[AnyRef])
|
||||||
|
}
|
||||||
|
|
||||||
case event @ Debug(logSource, message) ⇒
|
case event @ Debug(logSource, message) ⇒
|
||||||
Logger(logSource).debug("[{}] [{}]",
|
withMdc(mdcThreadAttributeName, event.thread.getName) {
|
||||||
event.thread.getName, message.asInstanceOf[AnyRef])
|
Logger(logSource).debug("{}", message.asInstanceOf[AnyRef])
|
||||||
|
}
|
||||||
|
|
||||||
case InitializeLogger(_) ⇒
|
case InitializeLogger(_) ⇒
|
||||||
log.info("Slf4jEventHandler started")
|
log.info("Slf4jEventHandler started")
|
||||||
sender ! LoggerInitialized
|
sender ! LoggerInitialized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def withMdc(name: String, value: String)(logStatement: ⇒ Unit) {
|
||||||
|
MDC.put(name, value)
|
||||||
|
try {
|
||||||
|
logStatement
|
||||||
|
} finally {
|
||||||
|
MDC.remove(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -424,7 +424,7 @@ object Dependency {
|
||||||
val Netty = "3.2.5.Final"
|
val Netty = "3.2.5.Final"
|
||||||
val Protobuf = "2.4.1"
|
val Protobuf = "2.4.1"
|
||||||
val Scalatest = "1.6.1"
|
val Scalatest = "1.6.1"
|
||||||
val Slf4j = "1.6.0"
|
val Slf4j = "1.6.4"
|
||||||
val Spring = "3.0.5.RELEASE"
|
val Spring = "3.0.5.RELEASE"
|
||||||
val Zookeeper = "3.4.0"
|
val Zookeeper = "3.4.0"
|
||||||
val Rabbit = "2.3.1"
|
val Rabbit = "2.3.1"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue