From be666b03eef1e085adc0749837480e0db7f811ad Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 22 Apr 2019 21:40:51 +0100 Subject: Trace Logging on Permission Denied & ColorFormat (#6618) * 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 * formatting changes * 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 * Remove isTrace() check from deferred func * Adjust repo and allow logging of team * use FormatInt instead of Itoa * Add blank line Signed-off-by: Andrew Thornton * Update access.go --- docs/content/doc/advanced/logging-documentation.en-us.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'docs/content/doc/advanced') diff --git a/docs/content/doc/advanced/logging-documentation.en-us.md b/docs/content/doc/advanced/logging-documentation.en-us.md index bef034e2e7..3af75c0d8f 100644 --- a/docs/content/doc/advanced/logging-documentation.en-us.md +++ b/docs/content/doc/advanced/logging-documentation.en-us.md @@ -362,6 +362,17 @@ also set the `resetBytes` to the cached `resetBytes`. The `colorBytes` and `resetBytes` are not exported to prevent accidental overwriting of internal values. +## ColorFormat & ColorFormatted + +Structs may implement the `log.ColorFormatted` interface by implementing the `ColorFormat(fmt.State)` function. + +If a `log.ColorFormatted` struct is logged with `%-v` format, its `ColorFormat` will be used instead of the usual `%v`. The full `fmt.State` will be passed to allow implementers to look at additional flags. + +In order to help implementers provide `ColorFormat` methods. There is a +`log.ColorFprintf(...)` function in the log module that will wrap values in `log.ColoredValue` and recognise `%-v`. + +In general it is recommended not to make the results of this function too verbose to help increase its versatility. Usually this should simply be an `ID`:`Name`. If you wish to make a more verbose result, it is recommended to use `%-+v` as your marker. + ## Log Spoofing protection In order to protect the logs from being spoofed with cleverly @@ -392,5 +403,5 @@ func newNewoneLogService() { } ``` -You should then add `newOneLogService` to `NewServices()` in +You should then add `newOneLogService` to `NewServices()` in `modules/setting/setting.go` -- cgit v1.2.3