-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add timestamp for debug logs #3110
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach doesn't seem very scalable. Each new added instruction will require the .Timestamp()
call. I think we should either define an helper function that will invoke:
gologger.Debug().Timestamp().Msgf("xxx)
or make this configurable via gologger itself, for example with global setter like:
gologger.EnableTimestamp()
gologger.EnableTimestampForLevel(Debug|Info|etc)
Also, I think that the timestamp should be disabled by default, as it can make the output easily unreadable (similarly to #2928)
Important note: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can test with the specific gologger commit with:
go get -v github.com/projectdiscovery/gologger@1c357ca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might need to point gologger with the correct reference:
go get -v github.com/projectdiscovery/gologger@xxx
github.com/projectdiscovery/gologger@1c357ca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- failing test
- update PR with a working example.
Proposed changes
Added timestamp on --debug
Changes Made
This PR includes the following changes:
SetTimestamp
method to theLogger
struct in gologger, which allows the user to enable or disable automatic timestamps for log messages, and to set the minimum level of log messages for which timestamps should be included.init()
function to set the default maximum log level toLevelInfo
, and added a timestamp option for the formatter and writer.How to use
The package provides a
DefaultLogger
variable that can be used to log messages with different levels (Debug
,Info
,Error
, etc.). You can configure the behavior of theDefaultLogger
using various methods, such asSetTimestamp
.An example of how to use this package:
Checklist