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

Pluggable logger #22

Merged
merged 6 commits into from
Jan 19, 2019
Merged

Conversation

shabbyrobe
Copy link
Collaborator

Here's a refreshingly simple one! A couple of the projects I'm integrating gofakes3 with use different loggers to the standard library's log. I've got a useful little bit of copy-pasta for situations like this which I've popped in to this PR (log.go). It lets you swap the log out and adapt whatever your project happens to be using easily, and fall back on the standard library's logger even more easily. The CLI tool and tester should both still work exactly as before: the CLI will still log to console, and the tester will still redirect the log to a file. Using gofakes3 directly will no longer generate log output by default though: you have to opt in to the old behaviour using gofakes3.WithGlobalLog().

Go 2 will hopefully convert log.Logger to an interface, which would obviate the need for all this if log library authors get on board and implement it, but we're not there yet unfortunately: golang/go#13182

@codecov-io
Copy link

codecov-io commented Jan 16, 2019

Codecov Report

Merging #22 into master will increase coverage by 0.44%.
The diff coverage is 89.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #22      +/-   ##
==========================================
+ Coverage   75.44%   75.89%   +0.44%     
==========================================
  Files          12       13       +1     
  Lines         900      925      +25     
==========================================
+ Hits          679      702      +23     
- Misses        154      155       +1     
- Partials       67       68       +1
Impacted Files Coverage Δ
log.go 100% <100%> (ø)
option.go 66.66% <100%> (+16.66%) ⬆️
cors.go 46.66% <66.66%> (ø) ⬆️
gofakes3.go 69.02% <82.14%> (-0.51%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 074ae5e...a58e1f8. Read the comment docs.

Copy link
Owner

@johannesboyne johannesboyne left a comment

Choose a reason for hiding this comment

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

Nice! Now GFS3 has it's pluggable logger!

@johannesboyne
Copy link
Owner

ups. I guess my conflict resolution broke it ;-) and I have to get into a meeting marathon now. Will fix later >.<

@shabbyrobe
Copy link
Collaborator Author

shabbyrobe commented Jan 18, 2019

Oops, totally my fault, I didn't consider the interaction between the two PRs properly. I've fixed it up now, the test should pass. Sorry 'bout that. I hope the meetings are swift, productive and focused! 😄

@johannesboyne johannesboyne merged commit 62d688c into johannesboyne:master Jan 19, 2019
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