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 ¶
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.
Click to show internal directories.
Click to hide internal directories.