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

Adding logger - guidance needed #23

Merged
merged 1 commit into from
Dec 9, 2018

Conversation

magicmark
Copy link
Contributor

@magicmark magicmark commented Feb 25, 2017

Hey! Thanks for the work on lemonade!

So I'm interested in adding a logger (#20) to work some other things out

I'm new to writing go code, so please excuse any errors - I also need a little guidance on how to get the logger instance into the rpc methods (since the server may set a different log level, it needs the right logger instance)
(EDIT: Looks like I can fix this with #21)

I also wanted to get your thoughts on how to do the logging - assuming we want log levels, it seems a 3rd party library would be better than the stdlib log package. I've done a some googling, and log15 seems reasonable - https://0value.com/about-Go-logging some comprehensive thoughts.

Cheers, lmk!

@pocke
Copy link
Member

pocke commented Feb 27, 2017

Thanks for your pull-request!

I also need a little guidance on how to get the logger instance into the rpc methods (since the server may set a different log level, it needs the right logger instance)

Does that mean using logger in Copy method for Clipboard or something? (e.g. https://github.com/pocke/lemonade/pull/23/files#diff-86c06ac664ab686be214d58c0a83b149R13 )
I think we have two way.
First, we can use global variable for logger. A scope for the variable is a bit wide(global, but unexported outside a package), but implementation is easy.

Second, we can extend the Clipboard struct. For example:

type Clipboard struct{
  logger log.Logger
}

clipboard := &Clipboard{
  logger: logger,
}
rpc.Regiser(clipboard)

In this way, the logger variable's scope is not wide. But I think the implementation is more difficult than the first way.

I also wanted to get your thoughts on how to do the logging - assuming we want log levels, it seems a 3rd party library would be better than the stdlib log package. I've done a some googling, and log15 seems reasonable - https://0value.com/about-Go-logging some comprehensive thoughts.

LGTM 👍


Could you use goimports ? I use this command for formatting go code and manage import external packages.

@mattn mattn mentioned this pull request Dec 9, 2018
@mattn mattn merged commit 2fc9086 into lemonade-command:master Dec 9, 2018
@mattn mattn mentioned this pull request Dec 9, 2018
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.

3 participants