chain

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package chain implements a logging chain.

RU: Package chain реализует цепочку логгирования.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(l ...log.Logger) log.Logger

New constructor of a logger that implements a chain of loggers l. You can specify an arbitrary number. If l == nil, logging will not be performed.

New конструктор логгера, реализующего цепочку из логгеров l. Можно указывать произвольное количество. Если l == nil, логгирование не будет осуществляться.

Example
package main

import (
	"bytes"
	"io"
	"os"

	origlogrus "github.com/sirupsen/logrus"

	log15orig "github.com/inconshreveable/log15"

	"github.com/ovsinc/multilog/chain"
	"github.com/ovsinc/multilog/log15"
	"github.com/ovsinc/multilog/logrus"
)

func LogfmtFormat() log15orig.Format {
	return log15orig.FormatFunc(func(r *log15orig.Record) []byte {
		buf := &bytes.Buffer{}

		_, _ = buf.Write([]byte("lvl="))
		_, _ = io.WriteString(buf, r.Lvl.String())

		_, _ = buf.Write([]byte(" msg=\""))
		_, _ = io.WriteString(buf, r.Msg)
		_, _ = buf.Write([]byte("\""))

		return buf.Bytes()
	})
}

func main() {
	l1 := origlogrus.New()
	l1.SetOutput(os.Stdout)
	l1.SetLevel(origlogrus.DebugLevel)
	l1.SetFormatter(&origlogrus.TextFormatter{
		DisableTimestamp: true,
	})

	l2 := log15orig.New()
	l2.SetHandler(log15orig.StreamHandler(os.Stdout, LogfmtFormat()))

	chainLog := chain.New(logrus.New(l1), log15.New(l2))
	chainLog.Infof("Hello %s", "world")

}
Output:

level=debug msg="Hello world"
lvl=info msg="Hello world"

Types

This section is empty.

Jump to

Keyboard shortcuts

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