Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s4s7/soglog
slog initializer for minimalist (Golang, Opentelemetry, Google Cloud)
https://github.com/s4s7/soglog
cloudlogging cloudtrace golang google-cloud opentelemetry slog
Last synced: 4 months ago
JSON representation
slog initializer for minimalist (Golang, Opentelemetry, Google Cloud)
- Host: GitHub
- URL: https://github.com/s4s7/soglog
- Owner: s4s7
- License: mit
- Created: 2024-05-06T11:56:41.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-05-28T16:26:39.000Z (8 months ago)
- Last Synced: 2024-07-11T12:32:03.128Z (7 months ago)
- Topics: cloudlogging, cloudtrace, golang, google-cloud, opentelemetry, slog
- Language: Go
- Homepage:
- Size: 32.2 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
# Minimalist Logger
based on slog with Otel for GoogleCloud
![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.21-%23007d9c)
[![GoDoc](https://godoc.org/github.com/samber/slog-multi?status.svg)](https://pkg.go.dev/github.com/s4s7/soglog)sog stands for **S**tructured **O**tel **G**oogleCloud, inspired by [clog](https://github.com/nownabe/clog).
Special thanks to nownabe.## Key Features
1. **When the log level is set to error, a stack trace will be displayed.**
| | |
|-------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|| 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. |2. **You can add additional information from the context (ctx) to labels.**
| | |
|-------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|| Insert code that corresponds to the following type during initialization
``type LabelFieldInjector func(ctx context.Context) (key, value string, found bool)`` |3. **You can initialize slog with a one-liner at server startup, allowing you to use its default slog methods throughout your application**
```golang
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`.