I am using log.Println() inside the router callback functions to print debug messages. These get printed to console but they don't have timestamps. How do I enable it log timestamps?
gin disables the log flags in debug.go#14.
I don't know the reason behind this, rather than hiding the timestamps when printing debug information when calling debugPrint here.
But you may enable them as so:
log.SetFlags(log.LstdFlags)
Or, including the file and line number:
log.SetFlags(log.LstdFlags | log.Lshortfile)
Thanks, it works after I did log.SetFlags(log.LstdFlags). This was what I wanted.
I think this should be reopened. If gin wants to use it's own logging format, it should use its own logger via log.New(). Under no circumstances should it be changing global settings in another package whose behavior others might depend on.
The last comment is more than a year old, but I just stumbled across the issue as well and I'm of the same opinion as @peragwin.
@bharatkrishna: Do you mind reopening the issue?
Does anyone from the Gin team want to share their thoughts?
@peragwin @bharatkrishna @philippgille See https://github.com/gin-gonic/gin/pull/1560
Most helpful comment
I think this should be reopened. If gin wants to use it's own logging format, it should use its own logger via log.New(). Under no circumstances should it be changing global settings in another package whose behavior others might depend on.