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

avoid logging in the library, and avoid using glog #63

Open
aybabtme opened this issue Jul 29, 2016 · 0 comments
Open

avoid logging in the library, and avoid using glog #63

aybabtme opened this issue Jul 29, 2016 · 0 comments

Comments

@aybabtme
Copy link

The library pulls in github.com/golang/glog for logging. That package installs global flags in the stdlib flag package, which means applications using embd get a bunch of flags pulled in by default, which is a bit unsightly.

For instance, I declared 3 flags for my app:

var (
    pinID     = flag.Int("pin", 10, "pin to use")
    direction = flag.String("direction", "in", "in|out")
    format    = flag.String("format", "hex", "hex|bin")
)
flag.Parse()

...yet glog, thru embd, pollutes my command with a bunch of flags.

$ uartdump -h
Usage of uartdump:
  -alsologtostderr
        log to standard error as well as files
  -direction string
        in|out (default "in")
  -format string
        hex|bin (default "hex")
  -log_backtrace_at value
        when logging hits line file:N, emit a stack trace
  -log_dir string
        If non-empty, write log files in this directory
  -logtostderr
        log to standard error instead of files
  -pin int
        pin to use (default 10)
  -stderrthreshold value
        logs at or above this threshold go to stderr
  -v value
        log level for V logs
  -vmodule value
        comma-separated list of pattern=N settings for file-filtered logging

Note that in general, it's a bit of an anti-pattern for libraries to log. There's some cases where it makes sense tho, and in those case libraries should avoid linking against a specific implementation and instead take an injectable interface.

I've seen only 1 such usage of glog and it feels to me that it isn't necessary. If my argument makes sense to you, I'm happy to send a PR.

@aybabtme aybabtme changed the title avoid using glog in the library avoid logging in the library, and avoid using glog Jul 29, 2016
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

No branches or pull requests

1 participant