You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
...giving the following output (using a gruvbox terminal color scheme):
30
30
31
-

31
+

32
32
33
33
This output is meant to be easily read by a developer working locally. However, you may want a more
34
34
structured format for production, such as JSON, to make log analysis easier. You can get both by
35
35
conditionally choosing the log handler for your application, e.g.:
36
36
37
37
```go
38
-
varhandler slog.Handler
38
+
varlogHandler slog.Handler
39
39
switch os.Getenv("ENVIRONMENT") {
40
40
case"PROD":
41
-
handler = slog.NewJSONHandler(os.Stdout, nil)
41
+
logHandler = slog.NewJSONHandler(os.Stdout, nil)
42
42
case"DEV":
43
-
handler = devlog.NewHandler(os.Stdout, nil)
43
+
logHandler = devlog.NewHandler(os.Stdout, nil)
44
44
}
45
45
46
-
slog.SetDefault(slog.New(handler))
46
+
slog.SetDefault(slog.New(logHandler))
47
47
```
48
48
49
49
## devlog/log
@@ -52,6 +52,34 @@ To complement `devlog`'s output handling, the
52
52
[`devlog/log`](https://pkg.go.dev/hermannm.dev/devlog/log) subpackage provides input handling. It is
53
53
a thin wrapper over the `slog` package, with utility functions for log message formatting.

82
+
55
83
## Credits
56
84
57
85
-[Jonathan Amsterdam](https://github.com/jba) for his fantastic
0 commit comments