Merge branch 'master' of github.com:jboner/akka

This commit is contained in:
Jonas Bonér 2011-11-28 17:07:37 +01:00
commit b4c09c6f7b
6 changed files with 49 additions and 17 deletions

View file

@ -142,7 +142,7 @@ akka.dev.conf:
::
akka {
event-handler-level = "DEBUG"
loglevel = "DEBUG"
}
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"
akka {
event-handler-level = "DEBUG"
loglevel = "DEBUG"
}
.. _-Dakka.output.config.source:

View file

@ -16,7 +16,7 @@ You can configure which event handlers should be registered at boot time. That i
akka {
# event handlers to register at boot time (EventHandler$DefaultListener logs to STDOUT)
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.

View file

@ -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
also need a SLF4J backend, we recommend:
also need a SLF4J backend, we recommend `Logback <http://logback.qos.ch/>`_:
.. 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
@ -20,8 +20,22 @@ This module includes a SLF4J Event Handler that works with Akka's standard Event
akka {
event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
event-handler-level = "DEBUG"
loglevel = "DEBUG"
}
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>

View file

@ -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::
akka {
event-handler-level = "DEBUG"
loglevel = "DEBUG"
actor {
debug {
receive = "true"

View file

@ -5,7 +5,7 @@
package akka.event.slf4j
import org.slf4j.{ Logger SLFLogger, LoggerFactory SLFLoggerFactory }
import org.slf4j.MDC
import akka.event.Logging._
import akka.actor._
@ -27,31 +27,49 @@ object Logger {
/**
* 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&#233;r</a>
*/
class Slf4jEventHandler extends Actor with SLF4JLogging {
val mdcThreadAttributeName = "sourceThread"
def receive = {
case event @ Error(cause, logSource, message)
Logger(logSource).error("[{}] [{}] [{}]",
Array[AnyRef](event.thread.getName, message.asInstanceOf[AnyRef], stackTraceFor(cause)))
withMdc(mdcThreadAttributeName, event.thread.getName) {
Logger(logSource).error(message.toString, cause)
}
case event @ Warning(logSource, message)
Logger(logSource).warn("[{}] [{}]",
event.thread.getName, message.asInstanceOf[AnyRef])
withMdc(mdcThreadAttributeName, event.thread.getName) {
Logger(logSource).warn("{}", message.asInstanceOf[AnyRef])
}
case event @ Info(logSource, message)
Logger(logSource).info("[{}] [{}]",
event.thread.getName, message.asInstanceOf[AnyRef])
withMdc(mdcThreadAttributeName, event.thread.getName) {
Logger(logSource).info("{}", message.asInstanceOf[AnyRef])
}
case event @ Debug(logSource, message)
Logger(logSource).debug("[{}] [{}]",
event.thread.getName, message.asInstanceOf[AnyRef])
withMdc(mdcThreadAttributeName, event.thread.getName) {
Logger(logSource).debug("{}", message.asInstanceOf[AnyRef])
}
case InitializeLogger(_)
log.info("Slf4jEventHandler started")
sender ! LoggerInitialized
}
def withMdc(name: String, value: String)(logStatement: Unit) {
MDC.put(name, value)
try {
logStatement
} finally {
MDC.remove(name)
}
}
}

View file

@ -424,7 +424,7 @@ object Dependency {
val Netty = "3.2.5.Final"
val Protobuf = "2.4.1"
val Scalatest = "1.6.1"
val Slf4j = "1.6.0"
val Slf4j = "1.6.4"
val Spring = "3.0.5.RELEASE"
val Zookeeper = "3.4.0"
val Rabbit = "2.3.1"