-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdoc.go
More file actions
32 lines (24 loc) · 1.08 KB
/
doc.go
File metadata and controls
32 lines (24 loc) · 1.08 KB
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
/*
Package devslog provides a [log/slog] handler that formats records where
message is followed by each of it's attributes on seperate lines.
It implements the [slog.Handler] interface to format the record's message.
The default [slog.TextHandler] output adds year/month/date which I rarely
find useful when working on code locally. This is what [slog.TextHandler]
default output looks like:
2022/11/08 15:28:26 INFO hello count=3 method=GET request=http://example.com
This package turns the above message into this:
15:28:26 INFO hello
↳ count: 3
↳ method: GET
↳ request: http://example.com
The devslog handler can be set as the default logger with:
devslog.SetDefault(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
})
The top-level slog functions [slog.Info], [slog.Debug], etc will all use this
handler to format the records. [SetDefault] also updates the default logger
used by the [log] package, so that existing applications that use [log.Printf]
and related functions will send log records to the logger's handler without
needing to be rewritten.
*/
package devslog