GitXplorerGitXplorer
e

logrus_stackdriver

public
10 stars
4 forks
0 issues

Commits

List of commits on branch master.
Verified
95900b449221990abca0982bc838e072e270c64d

Add error handler for Stackdriver error (#5)

eevalphobia committed 6 years ago
Unverified
d79cdd8d8e2fcaf0c958bcf08802cde751ba496f

Copy *logrus.Entry.Data map before modifying (#3)

bbradleyfalzon committed 7 years ago
Unverified
3ef27bcaba13d1d31acd991aec40d705e805c5a4

Update import path Sirupsen -> sirupsen (#1)

eevalphobia committed 8 years ago
Unverified
11a42b78cbc66734bf2172a9e5d143a100418d46

Update README

eevalphobia committed 8 years ago
Unverified
7c50cc0ae3b3971c17c54b4df646b27d943453f0

Fix not to delete the field in entry.Data

eevalphobia committed 8 years ago
Unverified
ddd979dcd4426d91815ee5cd7e7a37ac95e66592

Initial commit.

eevalphobia committed 8 years ago

README

The README file for this repository.

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:      "xxx@xxx.iam.gserviceaccount.com",
        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.