Iris: [FEATURE REQUEST] Human readable timestamp for JSON accesslogs

Created on 16 Oct 2020  路  6Comments  路  Source: kataras/iris

Describe the bug
Even after setting ac.TimeFormat = "2006-01-02 15:04:05", I'm still seeing that the timestamp field in the JSON accesslogs are still in unixtime.

To Reproduce
Load the below config and perform a HTTP request and check the timestamp field:

    ac.Async = true
    ac.IP = true
    ac.BytesReceivedBody = true
    ac.BytesSentBody = true
    ac.BytesReceived = true
    ac.BytesSent = true
    ac.BodyMinify = true
    ac.RequestBody = true
    ac.ResponseBody = false
    ac.KeepMultiLineError = true
    ac.PanicLog = accesslog.LogHandler
    ac.TimeFormat = "2006-01-02 15:04:05"

    // Set format to JSON
    ac.SetFormatter(&accesslog.JSON{})

Expected behavior
Timestamp format should be set as per the configuration.

Desktop (please complete the following information):

  • OS: Arch Linux

iris.Version

  • v12.2.0-alpha
implemented feature

All 6 comments

Hello @CSRaghunandan that's not necessarily a bug, it's expected to force-set to unix time, because JSON logs are mainly used to be proccesed by other programs. However, we can change that behavior by a setting. Give me some time to finish some other tasks and I am on it.

Hello @CSRaghunandan that's not necessarily a bug, it's expected to force-set to unix time, because JSON logs are mainly used to be proccesed by other programs. However, we can change that behavior by a setting. Give me some time to finish some other tasks and I am on it.

Correct, all production logs should have unix timestamp. But I wanted to use a human readable format when I am running tests on our service built on iris.

Give me some time to finish some other tasks and I am on it.

Thanks for the quick response.

It's done @CSRaghunandan. The new HumanTime option lives at the JSON formatter:

ac.SetFormatter(&accesslog.JSON{
    Indent:    "  ",
    HumanTime: true,
})

It works with and without Indent option (jsoniter and easyjson, for the fastest result possible).

You are welcome, as always!

That was incredibly fast! Thank you :)

I'll close the issue.

Also, when can we expect the next release to happen? I would want to use this feature for dev builds.

Hello @CSRaghunandan ,

You dont need to wait for a new release for your dev builds. Go to your project's directory and execute the installation command again: go get github.com/kataras/iris/v12@master. The @master is fetching without any cache.

Was this page helpful?
0 / 5 - 0 ratings