# README
logrus_stackdriver
Google Stackdriver logging Hook for Logrus 
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 Name | Description |
---|---|
message | if message is not set, entry.Message is added to log data in "message" field. |
log_name | log_name is a custom log name. If not set, defaultLogName is used as log name. |
http_request | http_request is *http.Request for detailed http logging. |
http_response | http_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.