| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"flag" |
| 6 |
"log/slog" |
| 7 |
"os" |
| 8 |
|
| 9 |
"github.com/chainguard-dev/clog" |
| 10 |
"github.com/chainguard-dev/clog/slag" |
| 11 |
) |
| 12 |
|
| 13 |
func main() { |
| 14 |
var level slag.Level |
| 15 |
flag.Var(&level, "log-level", "log level") |
| 16 |
flag.Parse() |
| 17 |
|
| 18 |
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: &level}))) |
| 19 |
|
| 20 |
log := clog.NewLogger(slog.Default()).With("a", "b") |
| 21 |
ctx := clog.WithLogger(context.Background(), log) |
| 22 |
|
| 23 |
|
| 24 |
clog.FromContext(ctx).With("foo", "bar").Debugf("hello debug world") |
| 25 |
clog.FromContext(ctx).With("info", true).Infof("hello info world") |
| 26 |
clog.FromContext(ctx).With("warn", 42).Warnf("hello warn world") |
| 27 |
|
| 28 |
|
| 29 |
clog.ErrorContext(ctx, "hello error world") |
| 30 |
} |