/
types_context.go
74 lines (57 loc) · 2.15 KB
/
types_context.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package types
import (
"context"
log "github.com/sirupsen/logrus"
)
// Level is a log level.
type Level log.Level
// These are the different logging levels.
const (
// PanicLevel level, highest level of severity. Logs and then calls panic
// with the message passed to Debug, Info, ...
PanicLevel Level = Level(log.PanicLevel) + iota
// FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even
// if the logging level is set to Panic.
FatalLevel
// ErrorLevel level. Logs. Used for errors that should definitely be noted.
// Commonly used for hooks to send errors to an error tracking service.
ErrorLevel
// WarnLevel level. Non-critical entries that deserve eyes.
WarnLevel
// InfoLevel level. General operational entries about what's going on
// inside the application.
InfoLevel
// DebugLevel level. Usually only enabled when debugging. Very verbose
// logging.
DebugLevel
// TraceLevel level. An even more verbose levle of logging than DebugLevel.
TraceLevel
)
// Context is a libStorage context.
type Context interface {
context.Context
FieldLogger
// WithValue returns a copy of parent in which the value associated with
// key is val.
WithValue(key, value interface{}) Context
// Join joins this context with another, such that value lookups will first
// first check the current context, and if no such value exist, a lookup
// will be performed against the right side.
Join(ctx context.Context) Context
}
// ContextLoggerFieldAware is used by types that will be logged by the
// Context logger. The key/value pair returned by the type is then emitted
// as part of the Context's log entry.
type ContextLoggerFieldAware interface {
// ContextLoggerField is the fields that is logged as part of a Context's
// log entry.
ContextLoggerField() (string, interface{})
}
// ContextLoggerFieldsAware is used by types that will be logged by the
// Context logger. The fields returned by the type are then emitted as part of
// the Context's log entry.
type ContextLoggerFieldsAware interface {
// ContextLoggerFields are the fields that are logged as part of a
// Context's log entry.
ContextLoggerFields() map[string]interface{}
}