mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 22:26:30 +00:00
78892847ee
util packages should have a few dependencies as possible, particularly from within the same repo, to prevent the application from creating import loops Signed-off-by: Jakub Sokołowski <jakub@status.im>
31 lines
751 B
Go
31 lines
751 B
Go
package logutils
|
|
|
|
import (
|
|
"gopkg.in/natefinch/lumberjack.v2"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
)
|
|
|
|
// FileOptions are all options supported by internal rotation module.
|
|
type FileOptions struct {
|
|
// Base name for log file.
|
|
Filename string
|
|
// Size in megabytes.
|
|
MaxSize int
|
|
// Number of rotated log files.
|
|
MaxBackups int
|
|
// If true rotated log files will be gzipped.
|
|
Compress bool
|
|
}
|
|
|
|
// FileHandlerWithRotation instantiates log.Handler with a configured rotation
|
|
func FileHandlerWithRotation(opts FileOptions, format log.Format) log.Handler {
|
|
logger := &lumberjack.Logger{
|
|
Filename: opts.Filename,
|
|
MaxSize: opts.MaxSize,
|
|
MaxBackups: opts.MaxBackups,
|
|
Compress: opts.Compress,
|
|
}
|
|
return log.StreamHandler(logger, format)
|
|
}
|