Skip to content

Commit

Permalink
fix log timestamp, akka#22774
Browse files Browse the repository at this point in the history
* regression introduced by akka#22716
  (never released)
  • Loading branch information
patriknw committed Apr 24, 2017
1 parent 64a3a9c commit e327c8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions akka-actor-tests/src/test/scala/akka/event/LoggerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import akka.event.Logging._
import akka.util.Helpers
import akka.event.Logging.InitializeLogger
import akka.event.Logging.Warning
import java.text.SimpleDateFormat

object LoggerSpec {

Expand Down Expand Up @@ -273,6 +274,17 @@ class LoggerSpec extends WordSpec with Matchers {
}
}

"StdOutLogger" must {
"format timestamp to with system default TimeZone" in {
val log = new StdOutLogger {}
val event = Info("test", classOf[String], "test")
// this was the format in Akka 2.4 and earlier
val dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS")
val expected = dateFormat.format(new Date(event.timestamp))
log.timestamp(event) should ===(expected)
}
}

"Ticket 3165 - serialize-messages and dual-entry serialization of LogEvent" must {
"not cause StackOverflowError" in {
implicit val s = ActorSystem("foo", ticket3165Config)
Expand Down
9 changes: 6 additions & 3 deletions akka-actor/src/main/scala/akka/event/Logging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import akka.dispatch.RequiresMessageQueue
import akka.event.Logging._
import akka.util.ReentrantGuard
import akka.util.Helpers.toRootLowerCase
import akka.{AkkaException, ConfigurationException}
import akka.{ AkkaException, ConfigurationException }

import scala.annotation.implicitNotFound
import scala.collection.immutable
import scala.concurrent.Await
import scala.language.existentials
import scala.util.control.{NoStackTrace, NonFatal}
import scala.util.control.{ NoStackTrace, NonFatal }
import java.time.ZoneId
import java.time.LocalDateTime

/**
* This trait brings log level handling to the EventStream: it reads the log
Expand Down Expand Up @@ -864,6 +866,7 @@ object Logging {
class LoggerInitializationException(msg: String) extends AkkaException(msg)

private val formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss.SSS")
private val timeZone = ZoneId.systemDefault()

trait StdOutLogger {

Expand All @@ -879,7 +882,7 @@ object Logging {
// format: ON

def timestamp(event: LogEvent): String = {
formatter.format(Instant.ofEpochMilli(event.timestamp))
formatter.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(event.timestamp), timeZone))
}

def print(event: Any): Unit = event match {
Expand Down

0 comments on commit e327c8c

Please sign in to comment.