Merge pull request #22777 from akka/wip-22774-fix-log-timestamp-patriknw

fix log timestamp, #22774
This commit is contained in:
Patrik Nordwall 2017-04-24 11:41:57 +02:00 committed by GitHub
commit e495408627
2 changed files with 18 additions and 3 deletions

View file

@ -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)

View file

@ -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 {