github.com/status-im/status-go@v1.1.0/logutils/logrotation.go (about)

     1  package logutils
     2  
     3  import (
     4  	"gopkg.in/natefinch/lumberjack.v2"
     5  
     6  	"github.com/ethereum/go-ethereum/log"
     7  )
     8  
     9  // FileOptions are all options supported by internal rotation module.
    10  type FileOptions struct {
    11  	// Base name for log file.
    12  	Filename string
    13  	// Size in megabytes.
    14  	MaxSize int
    15  	// Number of rotated log files.
    16  	MaxBackups int
    17  	// If true rotated log files will be gzipped.
    18  	Compress bool
    19  }
    20  
    21  // FileHandlerWithRotation instantiates log.Handler with a configured rotation
    22  func FileHandlerWithRotation(opts FileOptions, format log.Format) log.Handler {
    23  	logger := &lumberjack.Logger{
    24  		Filename:   opts.Filename,
    25  		MaxSize:    opts.MaxSize,
    26  		MaxBackups: opts.MaxBackups,
    27  		Compress:   opts.Compress,
    28  	}
    29  	return log.StreamHandler(logger, format)
    30  }