Documentation
¶
Index ¶
- func BindFlags(cmd *cobra.Command)
- func MustInit(conf LoggingConfig)
- func MustInitFromViper()
- func MustInitWithCtx(ctx context.Context, wg *sync.WaitGroup, conf LoggingConfig)
- func MustInitWithCtxFromViper(ctx context.Context, wg *sync.WaitGroup)
- func WithModule(module string) *logrus.Entry
- type LoggingConfig
- type OutputConfig
- type RotationConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustInit ¶
func MustInit(conf LoggingConfig)
MustInit sets up the logging system according to the provided LoggingConfig and log level. It configures the log level, adds an alert hook, sets a text formatter, and adapts the logger for Geth compatibility. In case of any error during initialization, this function will panic.
func MustInitFromViper ¶
func MustInitFromViper()
MustInitFromViper initializes the logging system using configurations from viper.
Precondition:
- Viper must be initialized with appropriate configurations before calling this function.
Panics:
- This function will panic if it encounters any errors during initialization.
func MustInitWithCtx ¶ added in v0.2.1
func MustInitWithCtx(ctx context.Context, wg *sync.WaitGroup, conf LoggingConfig)
MustInitWithCtx performs the similiar initializations as `MustInit` with support for graceful shutdown by accepting a context and a wait group.
func MustInitWithCtxFromViper ¶ added in v0.2.1
MustInitWithCtxFromViper performs the similar initializations as `MustInitFromViper` with support for graceful shutdown by accepting a context and a wait group.
Parameters:
- ctx: The context for graceful shutdown handling.
- wg: The wait group to track goroutines for shutdown synchronization.
func WithModule ¶ added in v0.7.6
WithModule returns a logger with module name and specific log level.
Note, the module name should not contain delimiters "=" and ",". Otherwise, the behavior is unknown.
Types ¶
type LoggingConfig ¶
type LoggingConfig struct {
Level string `default:"info"` // log level in format of "level,module1=level1,module2=level2"
ForceColor bool // helpful on windows
DisableColor bool // helpful to output logs in file
AlertHook hook.Config // alert hooking configurations
Output OutputConfig // output configurations
}
LoggingConfig logging configuration such as log level etc.,
type OutputConfig ¶ added in v0.3.0
type OutputConfig struct {
Type string `default:"stderr"` // Available output types are: stdout, stderr, file
FilePath string // Optional: File path for "file" type
Rotation RotationConfig // Optional: Rotation settings for "file" type
}
OutputConfig represents the output configuration.
type RotationConfig ¶ added in v0.3.0
type RotationConfig struct {
MaxSize int `default:"100"` // Maximum size of the log file in MB before rotation
MaxBackups int // Maximum number of backup files to retain (0 to keep all)
MaxAge int `default:"30"` // Maximum age of log files before deletion (e.g., 30 days)
Compress bool `default:"true"` // Whether to compress rotated log files
}
RotationConfig defines the rotation settings for log files.