-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Trace Logging on Permission Denied & ColorFormat #6618
Conversation
Structs can now implement log.ColorFormatted to provide their own colored format when logged with `%-v` or additional flags. Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #6618 +/- ##
==========================================
- Coverage 40.79% 40.73% -0.07%
==========================================
Files 421 421
Lines 57570 57866 +296
==========================================
+ Hits 23487 23569 +82
- Misses 30955 31168 +213
- Partials 3128 3129 +1
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.
One nit. Looks good otherwise.
Isn't |
Ah yes but constructing the trace call is not free - so if we can avoid constructing it at all that may make sense. A lot of the calls there are less complex than I originally had them because I moved functionality into colorformat, so we could remove a few of the IsTrace calls but not all |
This PR adds
log.Trace(...)
calls to Permission Denied events.It also adds a new additional way for providing colored logs for structs in a semi-standardised way. e.g.
Will log
Log me a user userID:username
with the userID being colored cyan and the username in bold.Structs that want to implement this need to provide a
ColorFormat(s fmt.State)
function which is very similar to theFormat(...)
function expected byfmt
(mainly lacking the rune - which would always be'v'
.) If you logged%-v
then this function will be called, and if more verbose output is possible a+
should be passed in the flags and inspected for withs.Flags('+')
inColorFormat
, e.g.log.Info("%-+v", perm)
to log a verbose version ofmodels.Permission
.