Skip to content

Commit f0af4e6

Browse files
committed
chore: add log examples
1 parent 8402c5a commit f0af4e6

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

examples/log/kod_gen.go

+47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/log/main.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log/slog"
6+
7+
"github.com/go-kod/kod"
8+
)
9+
10+
type app struct {
11+
kod.Implements[kod.Main]
12+
}
13+
14+
func main() {
15+
kod.Run(context.Background(), func(ctx context.Context, app *app) error {
16+
// default log level is info
17+
app.L(ctx).Info("hello world info")
18+
19+
// set log level to error
20+
kod.FromContext(ctx).LevelVar().Set(slog.LevelError)
21+
22+
// wont print
23+
app.L(ctx).Debug("hello world info1")
24+
// wont print
25+
app.L(ctx).Info("hello world info1")
26+
// will print
27+
app.L(ctx).Error("hello world error")
28+
29+
return nil
30+
})
31+
}

0 commit comments

Comments
 (0)