pplogrus

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

README

pplogrus

This package instruments the sirupsen/logrus package.

Installation

$ go get github.com/pinpoint-apm/pinpoint-go-agent/plugin/logrus
import "github.com/pinpoint-apm/pinpoint-go-agent/plugin/logrus"

Usage

PkgGoDev

This package allows additional transaction id and span id of the pinpoint span to be printed in the log message. Use the NewField or NewEntry and pass the logrus field back to the logger.

tracer := pinpoint.FromContext(ctx)
logger.WithFields(pplogrus.NewField(tracer)).Fatal("oh, what a wonderful world")
entry := pplogrus.NewEntry(tracer).WithField("foo", "bar")
entry.Error("entry log message")

You can use NewHook as the logrus.Hook. It is necessary to pass the context containing the pinpoint.Tracer to logrus.Logger.

logger.AddHook(pplogrus.NewHook())
entry := logger.WithContext(pinpoint.NewContext(context.Background(), tracer)).WithField("foo", "bar")
entry.Error("hook log message")
import (
    "github.com/sirupsen/logrus"
    "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/logrus"
)

func logging(w http.ResponseWriter, r *http.Request) {
    logger := logrus.New()
    tracer := pinpoint.TracerFromRequestContext(r)
    logger.WithFields(pplogrus.NewField(tracer)).Fatal("ohhh, what a world")
}

Full Example Source

Documentation

Overview

Package pplogrus instruments the sirupsen/logrus package (https://github.com/sirupsen/logrus).

This package allows additional transaction id and span id of the pinpoint span to be printed in the log message. Use the NewField or NewEntry and pass the logrus field back to the logger.

tracer := pinpoint.FromContext(ctx)
logger.WithFields(pplogrus.NewField(tracer)).Fatal("oh, what a wonderful world")

or

entry := pplogrus.NewEntry(tracer).WithField("foo", "bar")
entry.Error("entry log message")

You can use NewHook as the logrus.Hook. It is necessary to pass the context containing the pinpoint.Tracer to logrus.Logger.

logger.AddHook(pplogrus.NewHook())
entry := logger.WithContext(pinpoint.NewContext(context.Background(), tracer)).WithField("foo", "bar")
entry.Error("hook log message")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEntry

func NewEntry(tracer pinpoint.Tracer) *logrus.Entry

NewEntry returns a new *logrus.Entry from standard logger. The entry has the transaction id and the span id of a pinpoint span.

func NewField

func NewField(tracer pinpoint.Tracer) logrus.Fields

NewField returns a new logrus.Fields added the transaction id and the span id of a pinpoint span.

func NewHook

func NewHook() *hook

NewHook returns a new logrus.Hook ready to instrument.

func NewLoggerEntry

func NewLoggerEntry(logger *logrus.Logger, tracer pinpoint.Tracer) *logrus.Entry

NewLoggerEntry returns a new *logrus.Entry from the provided logger. The entry has the transaction id and the span id of a pinpoint span.

func WithField

func WithField(tracer pinpoint.Tracer) logrus.Fields

WithField is deprecated. Use NewField.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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