[Feature][Backend] Option for JSON logging
Search before asking
- [X] I had searched in the issues and found no similar feature requirement.
Use case
As an operator, I want to be able to have devlake backend logs output in JSON format
Description
Devlake backend is using github.com/sirupsen/logrus for logging and has hardcoded the logrus.TextFormatter. Logrus also has an option to use a JSONFormatter https://pkg.go.dev/github.com/sirupsen/logrus#JSONFormatter. Would be nice to have the option to get logs in JSON format.
Could be exposed via environment variable LOGGING_FORMAT=json with a default value of text.
Related issues
No response
Are you willing to submit a PR?
- [ ] Yes I am willing to submit a PR!
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Collecting votes
Heyy @Maniacal, I'm new to Dev-Lake. Looking at the above feature request, I can see that you want to add a JOSNFormatter to view the logs in JSON format. Correct me if I am wrong. We need to add a conditional statement where if the LOGGING_FORMAT is set to JSON, we intend the log to be in JSON format; otherwise, text by default.
We need to modify this file. https://github.com/apache/incubator-devlake/blob/00213f1833374897758b5c4a60be67d872de8d92/backend/impls/logruslog/init.go#L50-L53
Where the code should look something like this:
if format := os.Getenv("LOGGING_FORMAT"); format == "json" {
inner.SetFormatter(&logrus.JSONFormatter{
TimestampFormat: time.DateTime
})
} else {
inner.SetFormatter(&logrus.TextFormatter{
TimestampFormat: time.DateTime,
FullTimestamp: true,
})
}
According to me, this is the possible solution. Please share your thoughts on this and tell me whether I should open a PR for it.
Hi @hanshal101 . I've not developed on this project, but I have worked with logrus in the past and, yes, I believe that is all that would be required to enable this feature.
ohk should I open a PR to fix this
@Maniacal Would you like to take a look at the PR and see if it solves your problem? Thanks.
@Maniacal Would you like to take a look at the PR and see if it solves your problem? Thanks.
From a code perspective it looks like what we're looking for. Reached out to the guys who deploy it internally to see if they're setup to deploy a PR so we can functionally test.
Ok, sounds good @Maniacal