1
1
# 🧻 devslog - Go [ slog.Handler] ( https://pkg.go.dev/log/slog#Handler ) for development
2
- [ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://github.com/golang-cz/devslog/blob/master/LICENSE )
3
- [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/golang-cz/devslog )] ( https://goreportcard.com/report/github.com/golang-cz/devslog )
4
- [ ![ Go Reference] ( https://pkg.go.dev/badge/github.com/golang-cz/devslog.svg )] ( https://pkg.go.dev/github.com/golang-cz/devslog )
2
+
3
+ [ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://github.com/golang-cz/devslog/blob/master/LICENSE )
4
+ [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/golang-cz/devslog )] ( https://goreportcard.com/report/github.com/golang-cz/devslog )
5
+ [ ![ Go Reference] ( https://pkg.go.dev/badge/github.com/golang-cz/devslog.svg )] ( https://pkg.go.dev/github.com/golang-cz/devslog )
5
6
6
7
` devslog ` is a zero dependency structured logging handler for Go's [ ` log/slog ` ] ( https://pkg.go.dev/log/slog ) package with pretty and colorful output for developers.
7
8
8
9
### Devslog output
10
+
9
11
![ image] ( https://github.com/golang-cz/devslog/assets/17728576/cfdc1634-16fe-4dd0-a643-21bf519cd4fe )
10
12
11
13
#### Compared to
14
+
12
15
` TextHandler `
13
16
![ image] ( https://github.com/golang-cz/devslog/assets/17728576/49aab1c0-93ba-409d-8637-a96eeeaaf0e1 )
14
17
15
18
` JSONHandler `
16
19
![ image] ( https://github.com/golang-cz/devslog/assets/17728576/775af693-2f96-47e8-9190-5ead77b41a27 )
17
20
18
21
## Install
22
+
19
23
```
20
24
go get github.com/golang-cz/devslog@latest
21
25
```
22
26
23
27
## Examples
28
+
24
29
### Logger without options
30
+
25
31
``` go
26
32
logger := slog.New (devslog.NewHandler (os.Stdout , nil ))
27
33
@@ -30,6 +36,7 @@ slog.SetDefault(logger)
30
36
```
31
37
32
38
### Logger with custom options
39
+
33
40
``` go
34
41
// new logger with options
35
42
opts := &devslog.Options {
@@ -48,7 +55,9 @@ slog.SetDefault(logger)
48
55
```
49
56
50
57
### Logger with default slog options
58
+
51
59
Handler accepts default [ slog.HandlerOptions] ( https://pkg.go.dev/golang.org/x/exp/slog#HandlerOptions )
60
+
52
61
``` go
53
62
// slog.HandlerOptions
54
63
slogOpts := &slog.HandlerOptions {
@@ -72,6 +81,7 @@ slog.SetDefault(logger)
72
81
```
73
82
74
83
### Example usage
84
+
75
85
``` go
76
86
slogOpts := &slog.HandlerOptions {
77
87
AddSource : true ,
@@ -98,8 +108,9 @@ slog.SetDefault(logger)
98
108
```
99
109
100
110
## Options
111
+
101
112
| Parameter | Description | Default | Value |
102
- | -------------------- | ---------------------------------------------------------------- | ---------------- | ---------------------- |
113
+ | ------------------ | -------------------------------------------------------------- | -------------- | -------------------- |
103
114
| MaxSlicePrintSize | Specifies the maximum number of elements to print for a slice. | 50 | uint |
104
115
| SortKeys | Determines if attributes should be sorted by keys. | false | bool |
105
116
| TimeFormat | Time format for timestamp. | "[ 15:04:05] " | string |
@@ -111,3 +122,4 @@ slog.SetDefault(logger)
111
122
| ErrorColor | Color for Error level | devslog.Red | devslog.Color (uint) |
112
123
| MaxErrorStackTrace | Max stack trace frames for errors | 0 | uint |
113
124
| StringerFormatter | Use Stringer interface for formatting | false | bool |
125
+ | NoColor | Disable coloring | false | bool |
0 commit comments