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

Trace Logging on Permission Denied & ColorFormat #6618

Merged
merged 18 commits into from
Apr 22, 2019

Conversation

zeripath
Copy link
Contributor

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.

log.Info("Log me a user %-v", user)

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 the Format(...) function expected by fmt (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 with s.Flags('+') in ColorFormat, e.g. log.Info("%-+v", perm) to log a verbose version of models.Permission.

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]>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 14, 2019
@codecov-io
Copy link

codecov-io commented Apr 14, 2019

Codecov Report

Merging #6618 into master will decrease coverage by 0.06%.
The diff coverage is 26.72%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
routers/repo/issue_watch.go 0% <0%> (ø) ⬆️
routers/api/v1/repo/pull.go 17.58% <0%> (-0.13%) ⬇️
modules/context/permission.go 20.63% <0%> (-20%) ⬇️
routers/repo/issue.go 35.75% <0%> (-1.4%) ⬇️
models/org_team.go 50.38% <0%> (-0.69%) ⬇️
routers/api/v1/api.go 69.78% <0%> (-5.54%) ⬇️
routers/repo/wiki.go 49.68% <0%> (-1.27%) ⬇️
routers/user/home.go 38.03% <0%> (-0.58%) ⬇️
routers/repo/pull.go 36.13% <0%> (-0.54%) ⬇️
models/user.go 50.51% <100%> (+0.18%) ⬆️
... and 11 more

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 b83114f...3bbb616. Read the comment docs.

@zeripath zeripath mentioned this pull request Apr 14, 2019
7 tasks
@lafriks lafriks added the type/enhancement An improvement of existing functionality label Apr 15, 2019
@lafriks lafriks added this to the 1.9.0 milestone Apr 15, 2019
Copy link
Member

@techknowlogick techknowlogick left a 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.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 16, 2019
@adelowo
Copy link
Member

adelowo commented Apr 21, 2019

Isn't Trace implementation supposed to be a no-op if !log.IsTrace rather than check if it's Trace level all the time ?

@zeripath
Copy link
Contributor Author

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

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 21, 2019
@lafriks lafriks merged commit be666b0 into go-gitea:master Apr 22, 2019
@zeripath zeripath deleted the permissions-logging branch May 2, 2019 18:50
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants