glbr

package module
v0.0.0-...-cdb4503 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: MIT Imports: 10 Imported by: 0

README

Grouping Logs by Request

Google Cloud Platform: Stackdriver Logging client wrapper

How to use

  • simple logging

    package main
    
    import (
        "github.com/KawanoTakayuki/glbr"
    )
    
    func main() {
        log, err := glbr.NewLogging(context.Background(), "ProjectID", "LogID")
        if err != nil {
            panic(err.Error())
        }
        defer log.Close()
    
        glbr.Debugf(log.Context(), "log")
    }
    
  • request grouping log

    package main
    
    import (
        "context"
        "net/http"
    
        "github.com/KawanoTakayuki/glbr"
    )
    
    func main() {
        logService, err := glbr.NewLogging(context.Background(), "ProjectID", "LogID")
        if err != nil {
            panic(err.Error())
        }
        defer logService.Close() // close only once
    
        /*
            each request
        */
        groupLog := logService.GroupedBy("ParentLogID")
    
        // group
        http.Handle("/group", groupLog(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
            c := r.Context() // request context
            glbr.Debugf(c, "group log")
        })))
    
        // no group
        http.Handle("/no-group", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
            c := logService.Context() // glbr context
            glbr.Debugf(c, "no group log")
        }))
    
        http.ListenAndServe(":8080", nil)
    
        /*
            all request
        */
        http.HandleFunc("/all-group", func(w http.ResponseWriter, r *http.Request) {
            c := r.Context() // request context
            glbr.Debugf(c, "all group log")
        })
    
        http.ListenAndServe(":8080", groupLog(http.DefaultServeMux))
    }
    
Monitored Resource Types
  • sample

    func main() {
        log, err := glbr.NewLogging(context.Background(), "ProjectID", "LogID")
        if err != nil {
            panic(err.Error())
        }
        defer log.Close()
    
        ResourceLavel := map[string]string{"key": "value"}
        log = log.Option(glbr.MonitoredResource("ResorceType", ResourceLavel))
        glbr.Debugf(log.Context(), "log")
    }
    

Documentation

Index

Constants

View Source
const (
	// GAEApplication .
	GAEApplication = "gae_app"
	//CloudFunction .
	CloudFunction = "cloud_function"
)

Variables

This section is empty.

Functions

func Alertf

func Alertf(c context.Context, format string, value ...interface{})

Alertf Criticalf < Alertf

func Criticalf

func Criticalf(c context.Context, format string, value ...interface{})

Criticalf Errorf < Criticalf

func CustomSeverityf

func CustomSeverityf(c context.Context, severity int, format string, value ...interface{})

CustomSeverityf 0 < Debugf(100) < ... < Emergencyf(700)

func Debugf

func Debugf(c context.Context, format string, value ...interface{})

Debugf 0 < Debugf

func Emergencyf

func Emergencyf(c context.Context, format string, value ...interface{})

Emergencyf Alertf < Emergencyf

func Errorf

func Errorf(c context.Context, format string, value ...interface{})

Errorf Warningf < Errorf

func Infof

func Infof(c context.Context, format string, value ...interface{})

Infof Debugf < Infof

func Noticef

func Noticef(c context.Context, format string, value ...interface{})

Noticef Infof < Noticef

func Warningf

func Warningf(c context.Context, format string, value ...interface{})

Warningf Noticef < Warningf

Types

type GroupingHandler

type GroupingHandler func(http.Handler) http.Handler

GroupingHandler グループ化される処理

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option option interface

func BufferedByte

func BufferedByte(limit int) Option

BufferedByte ログバッファの最大サイズ Default: 1GiB

func CloudFunctionsResource

func CloudFunctionsResource() Option

CloudFunctionsResource cloudfunctions log resource https://cloud.google.com/functions/docs/env-var?hl=ja#environment_variables_set_automatically

func ConcurrentWrite

func ConcurrentWrite(limit int) Option

ConcurrentWrite ログエントリの同時書き込み数 Default: 1

func EntryByteLimit

func EntryByteLimit(limit int) Option

EntryByteLimit 送信するログエントリの最大サイズ Default: 0(無制限)

func EntryByteThreshold

func EntryByteThreshold(threshold int) Option

EntryByteThreshold バッファ可能なログエントリの最大サイズ Default: 1MiB

func EntryCount

func EntryCount(threshold int) Option

EntryCount バッファ可能なログエントリの最大数 Default: 1000

func Label

func Label(label map[string]string) Option

Label ログエントリに付加する共通ラベル

func MonitoredResource

func MonitoredResource(resourceType string, resourceLabel map[string]string) Option

MonitoredResource ログエントリに付加するリソースラベル https://cloud.google.com/monitoring/api/resources のResourceTypeのLabelsを自動で補完します。 Default: resourceType = project, resourceLabel = {"project_id": $PROJECT_ID}

func WriteDelay

func WriteDelay(threshold int) Option

WriteDelay ログエントリの遅延書き込み時間 Default: 1s

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service loggingService

func NewLogging

func NewLogging(projectID, logID string, opts ...option.ClientOption) (service Service, err error)

NewLogging 新しいLoggingServiceを取得する

func (Service) Close

func (s Service) Close() (err error)

Close serviceを閉じる

func (Service) Context

func (s Service) Context() context.Context

Context log service context

func (Service) GroupedBy

func (s Service) GroupedBy(parentLogID string) GroupingHandler

GroupedBy ログをリクエストでグループ化する

func (Service) Option

func (s Service) Option(opts ...Option) Service

Option log service option

func (Service) WithContext

func (s Service) WithContext(c context.Context) Service

WithContext 他のcontextを受け入れる

func (Service) WithIOWriter

func (s Service) WithIOWriter(w io.Writer) Service

WithIOWriter write buffer after log output

Jump to

Keyboard shortcuts

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