Categorygithub.com/evalphobia/logrus_stackdriver
modulepackage
0.2.2
Repository: https://github.com/evalphobia/logrus_stackdriver.git
Documentation: pkg.go.dev

# README

logrus_stackdriver

Build Status Coverage Status codecov GoDoc

Google Stackdriver logging Hook for Logrus :walrus:

Usage

import (
    "github.com/evalphobia/google-api-go-wrapper/config"
    "github.com/evalphobia/logrus_stackdriver"
    "github.com/sirupsen/logrus"
)

func main() {
    hook, err := logrus_stackdriver.NewWithConfig("project_id", "test_log", config.Config{
        Email:      "[email protected]",
        PrivateKey: "-----BEGIN PRIVATE KEY-----\nXXX\n-----END PRIVATE KEY-----\n",
    })

    // set custom fire level
    hook.SetLevels([]logrus.Level{
        logrus.PanicLevel,
        logrus.ErrorLevel,
        logrus.WarnLevel,
    })

    // ignore field
    hook.AddIgnore("context")

    // add custome filter
    hook.AddFilter("error", logrus_stackdriver.FilterError)


    // send log with logrus
    logger := logrus.New()
    logger.Hooks.Add(hook)
    logger.WithFields(f).Error("my_message") // send log data to Google Stackdriver logging API
}

Special fields

Some logrus fields have a special meaning in this hook.

Field NameDescription
messageif message is not set, entry.Message is added to log data in "message" field.
log_namelog_name is a custom log name. If not set, defaultLogName is used as log name.
http_requesthttp_request is *http.Request for detailed http logging.
http_responsehttp_response is *http.Response for detailed http logging.

# Functions

New returns initialized logrus hook for Stackdriver.
NewWithConfig returns initialized logrus hook for Stackdriver.

# Structs

StackdriverHook is logrus hook for Google Stackdriver.