65 | 65 |
// Option sets a parameter for the leveled logger.
|
66 | 66 |
type Option func(*logger)
|
67 | 67 |
|
68 | |
// AllowAll is an alias for AllowDebugAndAbove.
|
|
68 |
// AllowAll is an alias for AllowDebug.
|
69 | 69 |
func AllowAll() Option {
|
70 | |
return AllowDebugAndAbove()
|
|
70 |
return AllowDebug()
|
71 | 71 |
}
|
72 | 72 |
|
73 | |
// AllowDebugAndAbove allows all of the four default log levels.
|
74 | |
func AllowDebugAndAbove() Option {
|
75 | |
return allowed(levelDebug | levelInfo | levelWarn | levelError)
|
|
73 |
// AllowDebug allows error, warn, info and debug level log events to pass.
|
|
74 |
func AllowDebug() Option {
|
|
75 |
return allowed(levelError | levelWarn | levelInfo | levelDebug)
|
76 | 76 |
}
|
77 | 77 |
|
78 | |
// AllowInfoAndAbove allows the default info, warn, and error log levels.
|
79 | |
func AllowInfoAndAbove() Option {
|
80 | |
return allowed(levelInfo | levelWarn | levelError)
|
|
78 |
// AllowInfo allows error, warn and info level log events to pass.
|
|
79 |
func AllowInfo() Option {
|
|
80 |
return allowed(levelError | levelWarn | levelInfo)
|
81 | 81 |
}
|
82 | 82 |
|
83 | |
// AllowWarnAndAbove allows the default warn and error log levels.
|
84 | |
func AllowWarnAndAbove() Option {
|
85 | |
return allowed(levelWarn | levelError)
|
|
83 |
// AllowWarn allows error and warn level log events to pass.
|
|
84 |
func AllowWarn() Option {
|
|
85 |
return allowed(levelError | levelWarn)
|
86 | 86 |
}
|
87 | 87 |
|
88 | |
// AllowErrorOnly allows only the default error log level.
|
89 | |
func AllowErrorOnly() Option {
|
|
88 |
// AllowError allows only error level log events to pass.
|
|
89 |
func AllowError() Option {
|
90 | 90 |
return allowed(levelError)
|
91 | 91 |
}
|
92 | 92 |
|
93 | |
// AllowNone allows none of the default log levels.
|
|
93 |
// AllowNone allows no leveled log events to pass.
|
94 | 94 |
func AllowNone() Option {
|
95 | 95 |
return allowed(0)
|
96 | 96 |
}
|
|
100 | 100 |
}
|
101 | 101 |
|
102 | 102 |
// ErrNotAllowed sets the error to return from Log when it squelches a log
|
103 | |
// event below the configured filtering level. By default, ErrNotAllowed is
|
104 | |
// nil; in this case, the log event is squelched with no error.
|
|
103 |
// event disallowed by the configured Allow[Level] option. By default,
|
|
104 |
// ErrNotAllowed is nil; in this case the log event is squelched with no
|
|
105 |
// error.
|
105 | 106 |
func ErrNotAllowed(err error) Option {
|
106 | 107 |
return func(l *logger) { l.errNotAllowed = err }
|
107 | 108 |
}
|
|
115 | 116 |
}
|
116 | 117 |
|
117 | 118 |
// ErrNoLevel sets the error to return from Log when it squelches a log event
|
118 | |
// with no level. By default, ErrNoLevel is nil; in this case, the log event
|
119 | |
// is squelched with no error.
|
|
119 |
// with no level. By default, ErrNoLevel is nil; in this case the log event is
|
|
120 |
// squelched with no error.
|
120 | 121 |
func ErrNoLevel(err error) Option {
|
121 | 122 |
return func(l *logger) { l.errNoLevel = err }
|
122 | 123 |
}
|