-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add -v flag for verbose log to stdout #22
Conversation
Codecov Report
@@ Coverage Diff @@
## main #22 +/- ##
==========================================
- Coverage 86.34% 85.99% -0.36%
==========================================
Files 38 38
Lines 1985 1999 +14
==========================================
+ Hits 1714 1719 +5
- Misses 217 223 +6
- Partials 54 57 +3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this change!
The logger we've implemented here roughly matches what the standard library's log
package would give us with the following:
log.New(os.Stderr, "[gopatch] ", 0)
We could use that directly.
In a future version, we can use model events through a custom logger type that acts as a boundary between business logic and the output stream. For example, if we did,
type Logger interface {
ParseError(file string, err error)
PatchError(file string, err error)
Patched(file string)
}
Then an implementation could decide the messages and output of each method depending on verbosity and output level. This might become necessary if/when we add trace-level logging on matchers/replacers. Although I'd defer designing the logger interface until we need it.
Separately, I think I'd like to avoid the "[gopatch]" prefix completely to reduce output noise; users know what tool they're running, and if part of a script, adding the prefix is easy. So just the following, maybe:
log.New(os.Stder, "", 0) // no prefix, no timestamps
For the log messages themselves:
- we should maybe go for shorter messages
- we can include the errors in the message; this will cause double logging of those errors because we list them at the end, but that's probably okay in verbose mode: you get the error once when it happens, and an error summary at the end
So maybe something like:
path/to/file.go: patched
path/to/other/file.go: skipped
path/to/something.go: failed: [...]
Thanks for the feedback @abhinav! I've updated the PR to use standard |
Since the comment got hidden because of the suggestion, copying it here:
|
I was thinking we should go with stdout because I can imagine the output getting too messy to be human-parsable with large # of files, and I can imagine people piping it for filtering: |
This implements #7. User can specify
-v
or--verbose
flag to make gopatch print whether each file was patched or not to stdout.The
-v
short flag was being used for printing version number so I took it away from--version
and put it on--verbose
because that seems more conventional with CLI tools..Example output: