-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (53 loc) · 1.31 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"context"
"log/slog"
"os"
"runtime/debug"
"github.com/highlight/highlight/sdk/highlight-go"
"github.com/joho/godotenv"
sloghighlight "github.com/ngoldack/slog-highlight"
)
func main() {
err := godotenv.Load()
if err != nil {
panic(err)
}
if _, ok := os.LookupEnv("HIGHLIGHT_PROJECT_ID"); !ok {
panic("env HIGHLIGHT_PROJECT_ID not set")
}
info, ok := debug.ReadBuildInfo()
v := "local-dev"
if ok {
v = info.Main.Sum
}
highlight.SetProjectID(os.Getenv("HIGHLIGHT_PROJECT_ID"))
highlight.Start(
highlight.WithServiceName("slog-highlight-example-minimal"),
highlight.WithServiceVersion(v),
)
defer highlight.Stop()
// this logger only uses the highlight handler
// you will not see any output in the console, only in highlight
logger := slog.New(
sloghighlight.NewHighlightHandler(),
)
slog.SetDefault(logger)
ctx := context.Background()
type userKey string
uk := userKey("user")
uv := struct {
user string
}{
user: "test",
}
ctx = context.WithValue(ctx, uk, uv)
slog.Debug("Hello Debug!")
slog.DebugContext(ctx, "Hello Debug Context!")
slog.Info("Hello World!")
slog.InfoContext(ctx, "Hello World Context!")
slog.Warn("Hello Warn!")
slog.WarnContext(ctx, "Hello Warn Context!")
slog.Error("Hello Error!")
slog.ErrorContext(ctx, "Hello Error Context!")
}