Skip to content

Commit

Permalink
chore: add log examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq committed Feb 22, 2024
1 parent 8402c5a commit f0af4e6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
47 changes: 47 additions & 0 deletions examples/log/kod_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions examples/log/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"context"
"log/slog"

"github.com/go-kod/kod"
)

type app struct {
kod.Implements[kod.Main]
}

func main() {
kod.Run(context.Background(), func(ctx context.Context, app *app) error {
// default log level is info
app.L(ctx).Info("hello world info")

// set log level to error
kod.FromContext(ctx).LevelVar().Set(slog.LevelError)

// wont print
app.L(ctx).Debug("hello world info1")
// wont print
app.L(ctx).Info("hello world info1")
// will print
app.L(ctx).Error("hello world error")

return nil
})
}

0 comments on commit f0af4e6

Please sign in to comment.