zaptoseq

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 10 Imported by: 0

README

Zap to Seq

A hook for sending Zap logs to Seq.
Original package author: https://github.com/eliezedeck/gozap2seq

Usage

Import:

import zaptoseq "github.com/Sunlight-Rim/zaptoseq"


With one core:

    hook, err := zaptoseq.NewHook("http://localhost:5341", "token")
    if err != nil {
   	   panic(err)
    }

    log := hook.NewLogger(zap.NewDevelopmentConfig())

    log.Info("Hello, World!")

    hook.Wait()

Note: token can be an empty string.


With multiple cores:

    // Some Zap core
    stdoutCore := zapcore.NewCore(
        zapcore.NewConsoleEncoder(zap.NewProductionEncoderConfig()),
        zapcore.AddSync(os.Stdout),
        zapcore.DebugLevel,
    )

    hook, err := zaptoseq.NewHook("http://localhost:5341", "token")
    if err != nil {
   	   panic(err)
    }

    log := hook.NewLoggerWith(zap.NewDevelopmentConfig(), stdoutCore)

    // Will be sent to both Seq and stdout
    log.Info("Hello, World!")

    hook.Wait()


With multiple cores without DI:

    // Some Zap core
    stdoutCore := zapcore.NewCore(
        zapcore.NewConsoleEncoder(zap.NewProductionEncoderConfig()),
        zapcore.AddSync(os.Stdout),
        zapcore.DebugLevel,
    )

    hook, err := zaptoseq.NewHook("http://localhost:5341", "token")
    if err != nil {
   	   panic(err)
    }

    // Zap logger with Seq core and stdout core
    log := zap.New(zapcore.NewTee(
        stdoutCore,
        hook.NewCore(zap.NewDevelopmentConfig()),
    ), zap.AddCaller())

    // Will be sent to both Seq and stdout
    log.Info("Hello, World!")

    hook.Wait()

Documentation

Overview

Package zaptoseq provides a hook to send logs from Zap logger to Seq (https://datalust.co/seq).

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyURL = errors.New("empty Seq url")
View Source
var ErrRequestCreation = errors.New("cannot create a request to Seq")

Functions

This section is empty.

Types

type Hook

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

func NewHook

func NewHook(sequrl, token string) (*Hook, error)

NewHook creates a hook to Seq.

func (*Hook) DisableFallbackLogs

func (h *Hook) DisableFallbackLogs()

DisableFallbackLogs turns off sending errors during Seq request to the console.

func (*Hook) EnableFallbackLogs

func (h *Hook) EnableFallbackLogs()

EnableFallbackLogs turns on sending errors during Seq request to the console.

func (*Hook) NewCore

func (h *Hook) NewCore(zapconfig zap.Config) zapcore.Core

NewCore returns Zap core that sending logs to Seq.

func (*Hook) NewLogger

func (h *Hook) NewLogger(zapconfig zap.Config) *zap.Logger

NewLogger builts a Zap-logger that send logs just to Seq.

func (*Hook) NewLoggerWith

func (h *Hook) NewLoggerWith(zapconfig zap.Config, cores ...zapcore.Core) *zap.Logger

NewLoggerWith builts a Zap-logger that send logs to Seq and also to other cores.

func (*Hook) Wait

func (h *Hook) Wait()

Wait until all requests are completed.

func (*Hook) Write

func (h *Hook) Write(p []byte) (n int, err error)

Write writes log to Seq. Implements the Writer interface.

Jump to

Keyboard shortcuts

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