Skip to content
/ soglog Public

slog initializer for minimalist (Golang, Opentelemetry, Google Cloud)

License

Notifications You must be signed in to change notification settings

s4s7/soglog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

Minimalist Logger
based on slog with Otel for GoogleCloud

Go Version GoDoc

sog stands for Structured Otel GoogleCloud, inspired by clog. Special thanks to nownabe.

Key Features

  1. When the log level is set to error, a stack trace will be displayed.
image The display of stack traces can be easily controlled at initialization.
For example, you can configure it to hide stack traces locally, while enabling them on Google Cloud.
  1. You can add additional information from the context (ctx) to labels.
image Insert code that corresponds to the following type during initialization
type LabelFieldInjector func(ctx context.Context) (key, value string, found bool)
  1. You can initialize slog with a one-liner at server startup, allowing you to use its default slog methods throughout your application
slog.SetDefault(slog.New(soglog.NewCloudLoggingHandler("your-project-id", &soglog.Options{IsStackTraced: true, LabelFieldInjector: yourLabelFieldInjector})

Note

soglog is strictly designed within the functionalities of the slog to support cloud logging. Therefore, soglog supports only 4 log levels: Debug, Info, Warn, and Error.