Skip to content
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

Switch to logrus logger #22

Merged
merged 13 commits into from
May 21, 2017
Merged

Switch to logrus logger #22

merged 13 commits into from
May 21, 2017

Conversation

rishiloyola
Copy link
Collaborator

Reference issue #18

Copy link
Owner

@vkuznet vkuznet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if you walk through all log calls, from this PR it seems that we have not so many of them. Please check.

client/client.go Outdated
log.Println("Unable to resolve destination", dst, "known agents", remoteAgents)
log.WithFields(log.Fields{
"Destination": dst,
"known agents": remoteAgents,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep keys CamelCase, in this case "known agents" should be replaced with Agents. Also, I think you can simply use the same semantics as log.Println() shows and it will properly formatted. Please try out and experiement with that. The main point is to get log in json format. I also want to move logger definition into config, i.e. in config we should specify which logger we want to use, e.g.

    // set logger settings depending on configuration
    if strings.Contains(strings.ToLower(config.LogFormatter), "json") {
        log.SetFormatter(&log.JSONFormatter{})
    }
    if strings.Contains(strings.ToLower(config.LogLevel), "info") {
        log.SetLevel(log.InfoLevel)
    }
    if strings.Contains(strings.ToLower(config.LogLevel), "warn") {
        log.SetLevel(log.WarnLevel)
    }
    if strings.Contains(strings.ToLower(config.LogLevel), "err") {
        log.SetLevel(log.ErrorLevel)
    }
    if strings.Contains(strings.ToLower(config.LogLevel), "debug") {
        log.SetLevel(log.DebugLevel)
    }

client/client.go Outdated
log.Println("ERROR fail with transfer request to", r.Url)
log.WithFields(log.Fields{
"Url": r.Url,
}).Error("ERROR fail with transfer request to", r.Url)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can take advantage of logrus to report Error so we don't need ERROR in error message.

@@ -81,7 +82,7 @@ func main() {
config.Register = agent
}
if config.Register == "" {
log.Println("WARNING this agent is not registered with remote ones, either provide register in your config or invoke register API call")
log.Warn("WARNING this agent is not registered with remote ones, either provide register in your config or invoke register API call")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we don't need WARNING in a message.

@rishiloyola
Copy link
Collaborator Author

Yes, we have so many log calls. I am still making changes. Do not merge this request.

@vkuznet
Copy link
Owner

vkuznet commented May 17, 2017

Rishi, before you going further. I want to raise a question, do you really need to replace log.Println with log.WithFields, the problem with such replacement is that if we need to rollback to standard logger we can't do it since standard logger does not have method WithFields and we'll need to redo all the work again. It would be nice to have transparent switch. So, hold on changes and think about it.

@rishiloyola
Copy link
Collaborator Author

Without WithFields method, it will just add some prefix to logs. If you want to highlight fields and its values then we have to use WithFields method.

Reference : https://github.com/sirupsen/logrus#fields

@rishiloyola
Copy link
Collaborator Author

rishiloyola commented May 19, 2017

Also, logger is not fully compatible with log. If you want to use logger in business.go file then we need to make some changes in the interface of this function.

@vkuznet
Copy link
Owner

vkuznet commented May 19, 2017 via email

@rishiloyola
Copy link
Collaborator Author

Do you want to replace log by logrus in remaining files?

@vkuznet
Copy link
Owner

vkuznet commented May 19, 2017 via email

@rishiloyola
Copy link
Collaborator Author

@vkuznet You can now merge this PR.

@vkuznet vkuznet merged commit 809dadd into vkuznet:master May 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants