Skip to content

Commit

Permalink
logger configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Kuthan committed Jun 28, 2015
1 parent 7a4a9a1 commit aeabbfa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions project/ApplicationBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ object ApplicationBuild extends Build {

val customLibraryDependencies = Seq(
"com.typesafe.akka" %% "akka-actor" % Versions.akka,
"com.typesafe.akka" %% "akka-slf4j" % Versions.akka,
"com.typesafe.akka" %% "akka-testkit" % Versions.akka % "test",

"com.typesafe.akka" %% "akka-http-experimental" % Versions.akkaStream,
"com.typesafe.akka" %% "akka-http-testkit-experimental" % Versions.akkaStream % "test",

"org.slf4j" % "slf4j-api" % "1.7.10",
"ch.qos.logback" % "logback-classic" % "1.1.2",
"com.typesafe.scala-logging" %% "scala-logging" % "3.1.0",

"org.scalatest" %% "scalatest" % "2.2.4" % "test",
"org.scalamock" %% "scalamock-scalatest-support" % "3.2" % "test"
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
akka {
event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"

log-dead-letters = 10
log-dead-letters-during-shutdown = on

# Log the complete configuration at INFO level when the actor system is started.
# This is useful when you are uncertain of what configuration is used.
log-config-on-start = off
log-config-on-start = on

actor {
debug {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
</encoder>
</appender>

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/example-spray.log</file>
<append>true</append>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<logger name="akka" level="DEBUG"/>
<logger name="spray" level="DEBUG"/>

<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
</configuration>
4 changes: 3 additions & 1 deletion src/main/scala/example/ExampleApplication.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import akka.http.Http
import akka.http.server.Route
import akka.stream.ActorFlowMaterializer
import com.typesafe.config.ConfigFactory
import com.typesafe.scalalogging.LazyLogging

import scala.concurrent.ExecutionContext

object ExampleApplication extends App {
object ExampleApplication extends App with LazyLogging {

implicit val system = ActorSystem("example-spray")
implicit val executor = system.dispatcher
Expand All @@ -36,6 +37,7 @@ object ExampleApplication extends App {

val exampleApplication = new ExampleApplication(helloService)

logger.info("Binding ...")
Http().bindAndHandle(exampleApplication.routes, config.getString("http.interface"), config.getInt("http.port"))
}

Expand Down
10 changes: 7 additions & 3 deletions src/main/scala/example/HelloService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package example

import akka.actor.{Actor, Props}
import akka.actor.{ActorLogging, Actor, Props}
import com.typesafe.scalalogging.LazyLogging

object HelloService {

Expand All @@ -28,12 +29,15 @@ object HelloService {

}

class HelloService(msg: String) extends Actor {
class HelloService(msg: String) extends Actor with LazyLogging {

import HelloService._

override def receive: Receive = {
case SayHello(n) => sender() ! Hello(s"$msg $n")
case SayHello(n) => {
logger.info(s"Handle message $n")
sender() ! Hello(s"$msg $n")
}
}

}

0 comments on commit aeabbfa

Please sign in to comment.