Git Product home page Git Product logo

logrus_stackdriver's Introduction

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 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.

logrus_stackdriver's People

Contributors

evalphobia avatar bradleyfalzon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.