/
logger.go
51 lines (40 loc) · 1.89 KB
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package logging
const (
ErrKey = "error"
)
// ErrInfoExtractor defines a function signature for functions
// that can extract information from an error.
type ErrInfoExtractor func(error) string
type Fields map[string]interface{}
// Logger defines the repository interface for a generic application logger,
// intended to result in structured logging using the WithField(s) functions to
// add context to the logger.
//
// Implementations are expected to provide new instances of the Logger when returning from
// the WithField(s) functions to allow for the creation of child loggers that's subsequent use
// don't influence the parent.
type Logger interface {
// Error Used when an error has occurred that is not recoverable, and will most likely
// involve returning an error to the consumer/user. Implementations must include a stacktrace at this level.
Error(msg string)
// Warn Used when a potential issue may exist, but the system can continue to function.
Warn(msg string)
// Info Used when something of interest has occurred that is useful to have logged in a
// production setting.
Info(msg string)
// Debug Used when providing information on specific code paths with the application that are
// being executed that are not required in a production setting.
Debug(msg string)
// WithField returns a new instance of the Logger that has the specified field attached
// in all subsequent messages.
WithField(key string, value interface{}) Logger
// WithError provides a wrapper around WithField to add an error field to the logger,
// ensuring consistency of error message keys.
WithError(err error) Logger
// WithFields returns a new instance of the Logger that has the specified fields attached
// in all subsequent messages.
WithFields(fields Fields) Logger
// Flush ensures that any pending log messages are written out. For some implementations
// this function will be a no-op.
Flush() error
}