diff --git a/akka-actor-tests/src/test/scala/akka/event/LoggerSpec.scala b/akka-actor-tests/src/test/scala/akka/event/LoggerSpec.scala index 821643ceac..afbce32b03 100644 --- a/akka-actor-tests/src/test/scala/akka/event/LoggerSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/event/LoggerSpec.scala @@ -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 { @@ -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) diff --git a/akka-actor/src/main/scala/akka/event/Logging.scala b/akka-actor/src/main/scala/akka/event/Logging.scala index d53455cf0a..2b4cc35dbf 100644 --- a/akka-actor/src/main/scala/akka/event/Logging.scala +++ b/akka-actor/src/main/scala/akka/event/Logging.scala @@ -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 @@ -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 { @@ -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 {