[utils] Make logger use diode writer (#2357)

pull/2358/head
Daniel Van Der Maden 5 years ago committed by GitHub
parent d2a901dc49
commit f338c9a8fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      internal/utils/singleton.go

@ -4,7 +4,6 @@ package utils
import ( import (
"fmt" "fmt"
"io"
"os" "os"
"path" "path"
"sync" "sync"
@ -13,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/natefinch/lumberjack" "github.com/natefinch/lumberjack"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/diode"
) )
var ( var (
@ -73,7 +73,10 @@ func AddLogHandler(handler log.Handler) {
// GetLogInstance returns logging singleton. // GetLogInstance returns logging singleton.
func GetLogInstance() log.Logger { func GetLogInstance() log.Logger {
onceForLog.Do(func() { onceForLog.Do(func() {
ostream := log.StreamHandler(io.Writer(os.Stdout), log.TerminalFormat(false)) writer := diode.NewWriter(os.Stdout, 1000, 10*time.Millisecond, func(missed int) {
fmt.Printf("Logger Dropped %d messages", missed)
})
ostream := log.StreamHandler(writer, log.TerminalFormat(false))
logHandlers = append(logHandlers, ostream) logHandlers = append(logHandlers, ostream)
multiHandler := log.MultiHandler(logHandlers...) multiHandler := log.MultiHandler(logHandlers...)
glogger = log.NewGlogHandler(multiHandler) glogger = log.NewGlogHandler(multiHandler)
@ -118,7 +121,10 @@ func setZeroLoggerFileOutput(filepath string, maxSize int) error {
func Logger() *zerolog.Logger { func Logger() *zerolog.Logger {
if zeroLogger == nil { if zeroLogger == nil {
zerolog.TimeFieldFormat = time.RFC3339Nano zerolog.TimeFieldFormat = time.RFC3339Nano
logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}). writer := diode.NewWriter(os.Stderr, 1000, 10*time.Millisecond, func(missed int) {
fmt.Printf("Logger Dropped %d messages", missed)
})
logger := zerolog.New(zerolog.ConsoleWriter{Out: writer}).
Level(zeroLoggerLevel). Level(zeroLoggerLevel).
With(). With().
Caller(). Caller().

Loading…
Cancel
Save