Documentation ¶
Overview ¶
Package log implements standard go logging
For logging:
log.Info(ctx, "message", log.F{field: 42}) log.Error(...) log.Debug(...) log.Fatal(...)
By default, log.Debug is not emitted but instead it is cached. If a higher event arrives within a couple of minutes of the debug log, the cached debug log is emitted (with the correct older timestamp).
Guidance on what type of log to use ¶
Please see the confluence page for logging guidance: https://outreach-io.atlassian.net/wiki/spaces/EN/pages/699695766/Logging+Tracing+and+Metrics
Example ¶
Output: {"@timestamp":"2019-09-05T14:27:40Z","app.version":"testing","level":"INFO","message":"example","module":"github.com/getoutreach/gobox","myField":42} {"@timestamp":"2019-09-05T14:27:40Z","app.version":"testing","level":"WARN","message":"example","module":"github.com/getoutreach/gobox","myField":42} {"@timestamp":"2019-09-05T14:27:40Z","app.version":"testing","level":"ERROR","message":"example","module":"github.com/getoutreach/gobox","myField":42}
Example (AppName) ¶
Output: {"@timestamp":"2019-09-05T14:27:40Z","app.name":"app_name","app.version":"testing","level":"INFO","message":"orgful","module":"github.com/getoutreach/gobox","myField":42,"service_name":"app_name"}
Example (With_custom_event) ¶
Output: {"@timestamp":"2019-09-05T14:27:40Z","app.version":"testing","level":"INFO","message":"example","module":"github.com/getoutreach/gobox","myevent_field":"boo"}
Example (With_nested_custom_event) ¶
Output: {"@timestamp":"2019-09-05T14:27:40Z","app.version":"testing","error.cause":" error","error.data.myevent_field":"boo","level":"INFO","message":"example","module":"github.com/getoutreach/gobox","rootfield":"value"}
Index ¶
- func Debug(ctx context.Context, message string, m ...Marshaler)
- func Error(ctx context.Context, message string, m ...Marshaler)
- func Fatal(ctx context.Context, message string, m ...Marshaler)
- func Flush(ctx context.Context)
- func Info(ctx context.Context, message string, m ...Marshaler)
- func Output() io.Writer
- func Purge(ctx context.Context)
- func SetOutput(w io.Writer)
- func Warn(ctx context.Context, message string, m ...Marshaler)
- func With(m ...Marshaler) logger
- func Write(s string)
- type F
- type Many
- type Marshaler
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
Debug emits a log at DEBUG level but only if an error or fatal happens within 2min of this event
Example (With_error) ¶
Output: {"@timestamp":"2019-09-05T14:27:40Z","app.version":"testing","level":"DEBUG","message":"msg1","module":"github.com/getoutreach/gobox","myField":42} {"@timestamp":"2019-09-05T14:27:40Z","app.version":"testing","level":"ERROR","message":"msg2","module":"github.com/getoutreach/gobox","myField":42}
Example (Without_error) ¶
Output: {"@timestamp":"2019-09-05T14:27:40Z","app.version":"testing","level":"INFO","message":"debug","module":"github.com/getoutreach/gobox","myField":42} {"@timestamp":"2019-09-05T14:27:40Z","app.version":"testing","level":"DEBUG","message":"debug","module":"github.com/getoutreach/gobox","myField":42}
func Fatal ¶
Fatal emits a log at FATAL level and exits. This is for catastrophic unrecoverable errors.
func Info ¶
Info emits a log at INFO level. This is not filtered and meant for non-debug information.
func Purge ¶
Purge clears all debug logs without writing them out. This is useful to clear logs from a successful tests that we don't want output during a subsequent test
func SetOutput ¶
SetOutput can be used to set the output for the module Note: this function should not be used in production code outside of service startup. SetOutput can be used for tests that need to redirect or filter logs
func Warn ¶
Warn emits a log at WARN level. Warn logs are meant to be investigated if they reach high volumes.
Types ¶
type F ¶
F is a map of fields used for logging:
log.Info(ctx, "request started", log.F{"start_time": time.Now()})
When logging errors, use events.Err:
log.Error(ctx, "some failure", events.Err(err))
type Many ¶
Many aggregates marshaling of many items
This avoids having to build an append list and also simplifies code
type Marshaler ¶
Marshaler is the interface to be implemented by items that can be logged.
The MarshalLog function will be called by the logger with the addField function provided. The implementation an add logging fields using this function. The field value can itself be another Marshaler instance, in which case the field names are concatenated with dot to indicate nesting.