KO
|
EN
gitlite — search
Search
#python
#java
#python3
#arduino
#golang
#machine-learning
#rust
#html
#flask
#javascript
#seismology
#nodejs
slog-context
★ 24
Open GitHub ↗
slog: Context handler
Download README (.md)
Explore Similar Repositories
Fundamentals-of-Analog-Electronic-Techniques
:
模拟电子技术基础
lastfm-scrobbler
:
🎵 A Last.fm scrobbler via MPRIS2 in Linux, designed for media players without built-in support for Last.fm
f3rm.github.io
:
F3RM: Feature Fields for Robotic Manipulation - Website
STFormer
:
基于Transformer的雷达回波外推用于近期降水预测的研究
fastlane-plugin-rustore
:
Fastlane плагин для заливки приложений в Rustore
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
slog-context
?
Download (.md)
# slog: Context handler  A Context Handler for [slog](https://pkg.go.dev/log/slog) Go library. ## Install ```sh go get github.com/PumpkinSeed/slog-context ``` ## Usage GoDoc: [https://pkg.go.dev/github.com/PumpkinSeed/slog-context](https://pkg.go.dev/github.com/PumpkinSeed/slog-context) ### Example ```go package main import ( "context" "log/slog" "os" "github.com/PumpkinSeed/slog-context" ) type Struct struct { Number int64 String string } func main() { // Add slogcontext.Handler to slog slog.SetDefault(slog.New(slogcontext.NewHandler(slog.NewJSONHandler(os.Stdout, nil)))) // Add values to context ctx := slogcontext.WithValue(context.Background(), "number", 12) ctx = slogcontext.WithValue(ctx, "string", "data") ctx = slogcontext.WithValue(ctx, "struct", Struct{ Number: 42, String: "struct_data", }) // Perform error log slog.ErrorContext(ctx, "this is an error") } ``` ### Output ```json {"time":"2023-08-15T13:36:50.207418292+02:00","level":"ERROR","msg":"this is an error","number":12,"string":"data","struct":{"Number":42,"String":"struct_data"}} ```