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 18 commits into from Apr 22, 2019


7 participants
Copy link

commented Apr 14, 2019

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.

zeripath added some commits Apr 14, 2019

Add log.ColorFormat and log.ColorFormatted
Structs can now implement log.ColorFormatted to provide their own
colored format when logged with `%-v` or additional flags.

Signed-off-by: Andrew Thornton <>
Add basic ColorFormat to repository and user
Signed-off-by: Andrew Thornton <>
Add basic ColorFormat to access and unit
Signed-off-by: Andrew Thornton <>
Add ColorFormat to permission and on trace log it
Signed-off-by: Andrew Thornton <>
Add log.NewColoredIDValue to make ID value coloring consistent
Signed-off-by: Andrew Thornton <>
Add some better tracing to permission denied for read issues/pulls
Signed-off-by: Andrew Thornton <>
Add Trace logging on permission denied
Signed-off-by: Andrew Thornton <>

This comment has been minimized.

Copy link

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 referenced this pull request Apr 14, 2019


compare/create PR produces a 404 #6302

2 of 7 tasks complete

@lafriks lafriks added this to the 1.9.0 milestone Apr 15, 2019

zeripath added some commits Apr 15, 2019

Add blank line
Signed-off-by: Andrew Thornton <>
Copy link

left a comment

One nit. Looks good otherwise.

@GiteaBot GiteaBot added lgtm/need 1 and removed lgtm/need 2 labels Apr 16, 2019

zeripath added some commits Apr 17, 2019


This comment has been minimized.

Copy link

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 ?


This comment has been minimized.

Copy link
Contributor Author

commented Apr 21, 2019

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 and removed lgtm/need 1 labels Apr 21, 2019

@lafriks lafriks merged commit be666b0 into go-gitea:master Apr 22, 2019

2 checks passed

approvals/lgtm this commit looks good
continuous-integration/drone/pr Build is passing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.