Documentation ¶
Overview ¶
Package log provides wrappers around logging for gosecure. By default gosecure uses the log package from the standard library, bit it can support any log handler.
Index ¶
Examples ¶
Constants ¶
const InvalidLevel = "invalid level"
InvalidLevel is the key used to record an invalid log level.
Variables ¶
This section is empty.
Functions ¶
func Handle ¶
Handle a log event using the Listener set on DefaultListener. If this is nil do nothing.
Example ¶
package main import ( "fmt" "bitbucket.org/idomdavis/gosecure/log" ) func main() { // switch to log recorder temporarily listener := log.DefaultListener recorder := &log.Recorder{} log.DefaultListener = recorder defer func() { log.DefaultListener = listener }() // Call the handler log.Handle("Error", "Something went wrong", log.Detail{"k": "v"}) // Output the result fmt.Println(recorder.Output) }
Output: Error Something went wrong map[k:v]
Types ¶
type Detail ¶
type Detail map[string]interface{}
Detail is used to hold details of log message passed to a Listener.
type Listener ¶
type Listener interface { // Handle an log event at the given level. Handle(level, msg string, detail Detail) }
A Listener is used to listen for log events generated by gosecure and handle them accordingly.
var DefaultListener Listener
DefaultListener is the Listener used by the Handle function, and by extension all gosecure functions. By default it is nil and all log events are discarded.
type LogrusListener ¶
type LogrusListener struct{}
LogrusListener reports using the default logrus logger.
func (LogrusListener) Handle ¶
func (LogrusListener) Handle(level, msg string, detail Detail)
Handle errors using logrus. Invalid levels are logged as Errors and the invalid level included in the output.