Some users have requested ability to override the logrus date/time format to lower the precision--some log aggregation systems do not do well with the number of sub-second digits that are included in the default format. We need to investigate how to set the date/time format via the logrus API and then decide how to pipe the configuration down from the entrypoint.
@tsandall
Customizing the format of logrus timestamp needs the following two configurations.
FullTimestamp TimestampFormatpackage main
import (
"github.com/sirupsen/logrus"
)
func main() {
logrus.Info("before")
formatter := &logrus.TextFormatter{
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
}
logrus.SetFormatter(formatter)
logrus.Info("after")
}
$ INFO[0000] before
$ INFO[2020-05-20 21:23:18] after
How about adding log-timestamp-format flag to implement the date/time format injection?
It seems a kind of the same level logging option with log-level and log-format in runtime.go.
Of course, it must require the validation of the time format.
I like the idea of having a configurable log-timestamp-format option, seems like a pretty easy thing to add on to the opa run CLI too
馃憤 a --log-timestamp-format option seems nice. The only other option I could imagine is a less powerful flag that lets users limit the number of sub-second digits. The only benefit I can think of is that if/when we switch to another logging library, it might be easier to continue supporting? I don't feel strongly about this--let's just go with --log-timestamp-format.
Okay, I鈥檒l give it a try if it isn鈥檛 missing the point.
Is it better to wait until you members take this issue in the project TODO list?
@timakin if you can work on this feature that would be excellent! I think the places that will need to change are:
I'm not sure how best to test these changes (aside from doing it manually)--maybe @patrick-east has thoughts.
I'm not sure how best to test these changes (aside from doing it manually)--maybe @patrick-east has thoughts.
I'm not 100% sure, but I think you can have logrus write its output into any io.Writer so we should be able to use to start up the runtime (getting some logs emitted) and writing them into a buffer and then parse it and check the timestamp field format.
WRT testing, we could do something similar to this test.
Is somebody working on this issue? I would like to contribute!
@timakin are you planning to work on this ?
Most helpful comment
WRT testing, we could do something similar to this test.