slogcloudlogging

package module
v0.0.0-...-13306e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2023 License: MIT Imports: 4 Imported by: 0

README

slog: Cloud Logging handler

Go Version

A Google Cloud Logging Handler for slog Go library.

Install

go get github.com/PumpkinSeed/slog-cloudlogging

Usage

GoDoc: https://pkg.golang.ir/github.com/PumpkinSeed/slog-cloudlogging

Example
package main

import (
	"errors"
	"log/slog"
	"time"

	slogcloudlogging "github.com/PumpkinSeed/slog-cloudlogging"
)

func main() {
	googleHandler := slogcloudlogging.NewHandler("test", "test-logs", nil)
	googleHandler.AutoFlush()
	slog.SetDefault(slog.New(googleHandler))

	slog.Error("test message", slog.Any("error", errors.New("this is an error")))
	time.Sleep(2 * time.Second) // Wait for the Flush
}

Documentation

Index

Constants

View Source
const (
	DefaultGoogleAutoFlushInterval = 500
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Google

type Google struct {
	ProjectID         string
	LogName           string
	AutoFlushInterval int

	Handler        slog.Handler
	ForwardHandler bool
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(project string, logName string, opts *Opts) *Google

func (*Google) AutoFlush

func (g *Google) AutoFlush() chan bool

func (*Google) Enabled

func (g *Google) Enabled(ctx context.Context, level slog.Level) bool

func (*Google) Handle

func (g *Google) Handle(ctx context.Context, record slog.Record) error

func (*Google) Print

func (g *Google) Print(main Line)

func (*Google) WithAttrs

func (g *Google) WithAttrs(attrs []slog.Attr) slog.Handler

func (*Google) WithGroup

func (g *Google) WithGroup(name string) slog.Handler

type Line

type Line struct {
	Level     slog.Level             `json:"level,omitempty"`
	Timestamp int64                  `json:"timestamp,omitempty"`
	Time      string                 `json:"time,omitempty"`
	Data      map[string]interface{} `json:"data,omitempty"`
}

type Opts

type Opts struct {
	Handler           slog.Handler
	ForwardHandler    bool
	AutoFlushInterval int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL