@@ -30,6 +30,9 @@ const (
30
30
ErrorLevel = slog .LevelError
31
31
// WarnLevel level. Non-critical entries that deserve eyes.
32
32
WarnLevel = slog .LevelWarn
33
+ // NoticeLevel level. Normal but significant conditions. Conditions that are not error conditions, but that may
34
+ // require special handling. slog doesn't have a Notice level, so we use the average between Info and Warn.
35
+ NoticeLevel = (slog .LevelInfo + slog .LevelWarn ) / 2
33
36
// InfoLevel level. General operational entries about what's going on inside the application.
34
37
InfoLevel = slog .LevelInfo
35
38
// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
@@ -43,17 +46,20 @@ func logFuncAdapter(slogFunc func(ctx context.Context, msg string, args ...inter
43
46
}
44
47
45
48
var allLevels = []slog.Level {
46
- slog .LevelDebug ,
47
- slog .LevelInfo ,
48
- slog .LevelWarn ,
49
- slog .LevelError ,
49
+ DebugLevel ,
50
+ InfoLevel ,
51
+ NoticeLevel ,
52
+ WarnLevel ,
53
+ ErrorLevel ,
50
54
}
51
55
52
56
var defaultHandlers = map [Level ]Handler {
53
57
DebugLevel : logFuncAdapter (slog .DebugContext ),
54
58
InfoLevel : logFuncAdapter (slog .InfoContext ),
55
- WarnLevel : logFuncAdapter (slog .WarnContext ),
56
- ErrorLevel : logFuncAdapter (slog .ErrorContext ),
59
+ // slog doesn't have a Notice level, so in the default handler, we use Warn instead.
60
+ NoticeLevel : logFuncAdapter (slog .WarnContext ),
61
+ WarnLevel : logFuncAdapter (slog .WarnContext ),
62
+ ErrorLevel : logFuncAdapter (slog .ErrorContext ),
57
63
}
58
64
var handlers = maps .Clone (defaultHandlers )
59
65
var handlersMu = sync.RWMutex {}
@@ -166,6 +172,18 @@ func Infof(context context.Context, format string, args ...interface{}) {
166
172
logf (context , InfoLevel , format , args ... )
167
173
}
168
174
175
+ // Notice outputs messages with the level [NoticeLevel] (when that is enabled) using the
176
+ // configured logging handler.
177
+ func Notice (context context.Context , args ... interface {}) {
178
+ log (context , NoticeLevel , args ... )
179
+ }
180
+
181
+ // Noticef outputs messages with the level [NoticeLevel] (when that is enabled) using the
182
+ // configured logging handler.
183
+ func Noticef (context context.Context , format string , args ... interface {}) {
184
+ logf (context , NoticeLevel , format , args ... )
185
+ }
186
+
169
187
// Warning outputs messages with the level [WarningLevel] (when that is enabled) using the
170
188
// configured logging handler.
171
189
func Warning (context context.Context , args ... interface {}) {
0 commit comments