Skip to content
vlad-tokarevPublic

About

log/slog default attributes adapter for Google Cloud Logging

Topics

Resources

Stars

20 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sloggcp

sloggcp provides a simple implementation of the ReplaceAttr function for JSONHandler from slog.

This implementation adapts the default slog attributes to be compatible with Google Cloud Platform's Structured Logging.

By using sloggcp, you can ensure correct log severity display in the GCP Logs Viewer and proper representation of other attributes.

It is applicable to any GCP service that delivers logs via Logging agent.

For example, CloudRun, etc.

Usage

Override default attributes

package main

import (
	"github.com/vlad-tokarev/sloggcp"
	"log/slog"
	"os"
)

func main() {

	logger := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
		ReplaceAttr: sloggcp.ReplaceAttr,
		AddSource:   true,
		Level:       slog.LevelDebug,
	}))
	slog.SetDefault(logger)
}

About

log/slog default attributes adapter for Google Cloud Logging

Topics

Resources

Stars

20 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages