pubsub_logrus

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pubsub_logrus contains middleware which logs messages using the logrus structured logger (see https://github.com/sirupsen/logrus).

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLoggingHandler

func NewLoggingHandler(entry *logrus.Entry, next pubsub_middleware.HandlerFunc, opts ...Option) pubsub_middleware.HandlerFunc

NewLoggingHandler returns a new logging handler middleware which uses logrus as the logger.

Example
package main

import (
	"context"
	"fmt"
	"log"

	pubsub_logrus "github.com/bvwells/pubsub-middleware/logging/logrus"
	"github.com/sirupsen/logrus"

	"cloud.google.com/go/pubsub"
)

func main() {
	ctx := context.Background()

	client, err := pubsub.NewClient(ctx, "project-id")
	if err != nil {
		log.Fatal(err)
	}

	entry := logrus.NewEntry(logrus.New())

	// Use a callback to receive messages via subscription.
	sub := client.Subscription("subscription")
	err = sub.Receive(ctx, pubsub_logrus.NewLoggingHandler(entry, func(ctx context.Context, m *pubsub.Message) {
		fmt.Println(m.Data)
		m.Ack() // Acknowledge that we've consumed the message.
	}))
	if err != nil {
		log.Println(err)
	}
}
Output:

Types

type MessageProducer

type MessageProducer func(ctx context.Context, format string, entry *logrus.Entry, fields logrus.Fields)

MessageProducer produces log messages.

type Option

type Option func(*options)

Option describes a logging option.

func WithMessageProducer

func WithMessageProducer(messageFunc MessageProducer) Option

WithMessageProducer overrides the default message producer for producing log messages.

Jump to

Keyboard shortcuts

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