https://github.com/arran4/gaelogger
Another google apps engine go logger this one is for the new go111+ world..
https://github.com/arran4/gaelogger
go golang google-app-engine google-app-engine-logger library logger-abstraction
Last synced: 10 days ago
JSON representation
Another google apps engine go logger this one is for the new go111+ world..
- Host: GitHub
- URL: https://github.com/arran4/gaelogger
- Owner: arran4
- License: mit
- Created: 2020-01-08T06:01:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2026-04-25T03:39:03.000Z (about 2 months ago)
- Last Synced: 2026-04-25T05:27:06.680Z (about 2 months ago)
- Topics: go, golang, google-app-engine, google-app-engine-logger, library, logger-abstraction
- Language: Go
- Homepage: https://pkg.go.dev/github.com/arran4/gaelogger
- Size: 133 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Note on `slog` and Ecosystem Changes
As of Go 1.21, the Go standard library includes [log/slog](https://pkg.go.dev/log/slog), a structured logging package. This is now the recommended way to perform structured logging in Go applications.
For Google Cloud (App Engine, Cloud Run, Cloud Functions), writing structured JSON logs to `stdout`/`stderr` is the recommended approach. `slog` with `JSONHandler` supports this natively.
## Resources
* [Structured Logging with slog](https://go.dev/blog/slog) (Official Go Blog)
* [log/slog documentation](https://pkg.go.dev/log/slog)
* [Resources for slog](https://go.dev/wiki/Resources-for-slog) (Community Wiki)
* [Structured logging in Google Cloud](https://cloud.google.com/logging/docs/structured-logging)
## How to Migrate to `slog`
Instead of using this package, you can use `slog` directly. To make `slog` compatible with Google Cloud Logging's expectations (e.g., using `severity` instead of `level`), you can configure the handler like this:
```go
import (
"log/slog"
"os"
)
func init() {
// Configure slog to use JSON handler and map LevelKey to "severity"
opts := &slog.HandlerOptions{
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
// Google Cloud Logging uses "severity" instead of "level"
if a.Key == slog.LevelKey {
return slog.Attr{Key: "severity", Value: a.Value}
}
return a
},
}
logger := slog.New(slog.NewJSONHandler(os.Stdout, opts))
slog.SetDefault(logger)
}
func handle(w http.ResponseWriter, r *http.Request) {
// Use slog.Info, slog.Error, etc.
slog.Info("handling request",
"method", r.Method,
"path", r.URL.Path,
"query", r.URL.RawQuery,
)
}
```
---
# Another google apps engine go logger this one is for the new go111+ world..
Usage is simple:
```go
import (
"github.com/arran4/gaelogger"
"net/http"
)
func init() {
http.HandleFunc("/", handle)
}
func handle(writer http.ResponseWriter, request *http.Request) {
logger := gaelogger.NewLogger(request)
defer logger.Close()
logger.Infof("%s request: %v %v", request.Method, request.URL.RawPath, request.URL.RawQuery)
}
```