zapmixin

package module
v0.0.0-...-78ee43a Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: MIT Imports: 7 Imported by: 0

README

zapmixin

Go Report Card

Hook for sending events zap logger to mixin.

Usage

package main

import (
	"github.com/fox-one/mixin-sdk-go"
	"github.com/xwjdsh/zapmixin"
	"go.uber.org/zap"
)

func main() {
	client, err := mixin.NewFromKeystore(&mixin.Keystore{
		ClientID:   "<client_id>",
		SessionID:  "<session_id>",
		PrivateKey: "<private_key>",
		PinToken:   "<pin_token>",
		Scope:      "<scope>",
	})
	if err != nil {
		panic(err)
	}

	conversations := []string{"<conversation_id>"}
	h, err := zapmixin.New(client, conversations)

	logger, _ := zap.NewProduction()
	logger.WithOptions(zap.Hooks(h.Hook()))

	logger.Info("info")
	logger.Warn("warn")
	logger.Error("error")
}

Parameters

Required
Optional
  • WithThresholdLevel - Level threshold, the default level is WARN.
  • WithFixedLevel - Only the given level will send the message.
  • WithSync - The default is to send messages to mixin asynchronously.
  • WithFormatter - Custom formatter.
  • WithFilter - Filters are applied to messages to determine if any entry should not be send out.
  • WithAfter - When the message is sent, it will be called.

Installation

go get github.com/xwjdsh/zapmixin

Credits

Based on zaptelegram.

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func New

func New(client *mixin.Client, conversations []string, opts ...Option) (*Handler, error)

func (*Handler) Apply

func (h *Handler) Apply(opts ...Option) error

func (*Handler) Client

func (h *Handler) Client() *mixin.Client

func (*Handler) Hook

func (h *Handler) Hook() func(zapcore.Entry) error

type MixinClient

type MixinClient interface {
	SendMessage(ctx context.Context, message *mixin.MessageRequest) error
}

type Option

type Option func(*Handler) error

func WithAfter

func WithAfter(f func(zapcore.Entry, *mixin.MessageRequest, error) error) Option

func WithFilter

func WithFilter(f func(e zapcore.Entry) bool) Option

func WithFixedLevel

func WithFixedLevel(l zapcore.Level) Option

func WithFormatter

func WithFormatter(f func(e zapcore.Entry) string) Option

func WithSync

func WithSync() Option

func WithThresholdLevel

func WithThresholdLevel(l zapcore.Level) Option

Jump to

Keyboard shortcuts

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