logrus

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package logrus provides benchmarking tools for comparing Logrus and Bolt performance.

Package logrus provides compatibility layer and migration tools for Logrus users.

Package logrus provides examples demonstrating migration from Logrus to Bolt.

Package logrus provides code transformation tools for migrating from Logrus to Bolt.

Index

Constants

This section is empty.

Variables

View Source
var StandardLogger = New()

StandardLogger returns the standard logger.

Functions

func AddHook

func AddHook(hook Hook)

AddHook adds a hook to the standard logger.

func BenchmarkBoltComplexStructure

func BenchmarkBoltComplexStructure(b *testing.B)

BenchmarkBoltComplexStructure benchmarks complex structured logging with Bolt.

func BenchmarkBoltErrorLogging

func BenchmarkBoltErrorLogging(b *testing.B)

BenchmarkBoltErrorLogging benchmarks Bolt error logging.

func BenchmarkBoltSimpleLogging

func BenchmarkBoltSimpleLogging(b *testing.B)

BenchmarkBoltSimpleLogging benchmarks simple Bolt logging.

func BenchmarkBoltStructuredLogging

func BenchmarkBoltStructuredLogging(b *testing.B)

BenchmarkBoltStructuredLogging benchmarks Bolt structured logging.

func BenchmarkBoltWithContext

func BenchmarkBoltWithContext(b *testing.B)

BenchmarkBoltWithContext benchmarks Bolt context logging.

func BenchmarkLogrusComplexStructure

func BenchmarkLogrusComplexStructure(b *testing.B)

BenchmarkLogrusComplexStructure benchmarks complex structured logging with Logrus.

func BenchmarkLogrusErrorLogging

func BenchmarkLogrusErrorLogging(b *testing.B)

BenchmarkLogrusErrorLogging benchmarks Logrus error logging.

func BenchmarkLogrusSimpleLogging

func BenchmarkLogrusSimpleLogging(b *testing.B)

BenchmarkLogrusSimpleLogging benchmarks simple Logrus logging.

func BenchmarkLogrusStructuredLogging

func BenchmarkLogrusStructuredLogging(b *testing.B)

BenchmarkLogrusStructuredLogging benchmarks Logrus structured logging.

func BenchmarkLogrusWithContext

func BenchmarkLogrusWithContext(b *testing.B)

BenchmarkLogrusWithContext benchmarks Logrus context logging.

func ConcurrentLoggingBenchmark

func ConcurrentLoggingBenchmark()

ConcurrentLoggingBenchmark demonstrates concurrent logging performance.

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Debugln

func Debugln(args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Errorln

func Errorln(args ...interface{})

func ExampleBasicLogging

func ExampleBasicLogging()

ExampleBasicLogging demonstrates basic logging migration from Logrus to Bolt.

func ExampleCompatibilityLayer

func ExampleCompatibilityLayer()

ExampleCompatibilityLayer demonstrates using the compatibility layer for gradual migration.

func ExampleContextLogging

func ExampleContextLogging()

ExampleContextLogging demonstrates context-based logging migration.

func ExampleErrorHandling

func ExampleErrorHandling()

ExampleErrorHandling demonstrates error handling migration.

func ExampleFieldTypes

func ExampleFieldTypes()

ExampleFieldTypes demonstrates various field types migration.

func ExampleFormatterMigration

func ExampleFormatterMigration()

ExampleFormatterMigration demonstrates formatter migration strategies.

func ExampleFullMigrationWorkflow

func ExampleFullMigrationWorkflow()

ExampleFullMigrationWorkflow demonstrates a complete migration workflow.

func ExampleHookMigration

func ExampleHookMigration()

ExampleHookMigration demonstrates how to handle Logrus hooks migration.

func ExampleLevelBasedLogging

func ExampleLevelBasedLogging()

ExampleLevelBasedLogging demonstrates different log levels.

func ExampleLoggerConfiguration

func ExampleLoggerConfiguration()

ExampleLoggerConfiguration demonstrates logger configuration migration.

func ExampleMigrationSteps

func ExampleMigrationSteps()

ExampleMigrationSteps demonstrates a step-by-step migration approach.

func ExamplePerformanceComparison

func ExamplePerformanceComparison()

ExamplePerformanceComparison demonstrates the performance improvement when migrating.

func ExampleStructuredLogging

func ExampleStructuredLogging()

ExampleStructuredLogging demonstrates structured logging patterns.

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Fatalln

func Fatalln(args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func Infoln

func Infoln(args ...interface{})

func IsLevelEnabled

func IsLevelEnabled(level Level) bool

IsLevelEnabled checks if the standard logger will output a logging event.

func MemoryUsageTest

func MemoryUsageTest()

MemoryUsageTest demonstrates memory usage patterns.

func Panic

func Panic(args ...interface{})

func Panicf

func Panicf(format string, args ...interface{})

func Panicln

func Panicln(args ...interface{})

func Print

func Print(args ...interface{})

func PrintPerformanceResults

func PrintPerformanceResults(results []PerformanceComparisonResult)

PrintPerformanceResults prints performance comparison results in a readable format.

func Printf

func Printf(format string, args ...interface{})

func Println

func Println(args ...interface{})

func SetFormatter

func SetFormatter(formatter Formatter)

SetFormatter sets the standard logger formatter.

func SetLevel

func SetLevel(level Level)

SetLevel sets the standard logger level.

func SetOutput

func SetOutput(out io.Writer)

SetOutput sets the standard logger output.

func Sprint

func Sprint(args ...interface{}) string

func Sprintf

func Sprintf(format string, args ...interface{}) string

func Sprintln

func Sprintln(args ...interface{}) string

func Trace

func Trace(args ...interface{})

Standard logging methods

func Tracef

func Tracef(format string, args ...interface{})

Formatted logging methods

func Traceln

func Traceln(args ...interface{})

Line logging methods

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

func Warning

func Warning(args ...interface{})

func Warningf

func Warningf(format string, args ...interface{})

func Warningln

func Warningln(args ...interface{})

func Warnln

func Warnln(args ...interface{})

Types

type BenchmarkReport

type BenchmarkReport struct {
	Timestamp   string                        `json:"timestamp"`
	Summary     BenchmarkSummary              `json:"summary"`
	Comparisons []PerformanceComparisonResult `json:"comparisons"`
	Conclusions []string                      `json:"conclusions"`
}

BenchmarkReport generates a detailed benchmark report.

func GenerateBenchmarkReport

func GenerateBenchmarkReport() *BenchmarkReport

GenerateBenchmarkReport creates a comprehensive benchmark report.

type BenchmarkSummary

type BenchmarkSummary struct {
	TotalTests               int     `json:"total_tests"`
	AverageSpeedImprovement  float64 `json:"average_speed_improvement"`
	AverageAllocImprovement  float64 `json:"average_alloc_improvement"`
	AverageMemoryImprovement float64 `json:"average_memory_improvement"`
	MaxSpeedImprovement      float64 `json:"max_speed_improvement"`
	MinSpeedImprovement      float64 `json:"min_speed_improvement"`
}

BenchmarkSummary provides overall summary statistics.

type CustomHandler

type CustomHandler struct {
	// contains filtered or unexported fields
}

CustomHandler demonstrates how to implement hook-like functionality in Bolt.

func (*CustomHandler) Write

func (h *CustomHandler) Write(e *bolt.Event) error

Write implements bolt.Handler interface and adds custom logic.

type Entry

type Entry struct {
	Logger  *Logger
	Data    Fields
	Time    time.Time
	Level   Level
	Caller  *runtime.Frame
	Message string
	Buffer  []byte
	Context context.Context
	// contains filtered or unexported fields
}

Entry represents a log entry.

func WithContext

func WithContext(ctx context.Context) *Entry

WithContext creates an entry from the standard logger with a context.

func WithError

func WithError(err error) *Entry

WithError creates an entry from the standard logger with an error field.

func WithField

func WithField(key string, value interface{}) *Entry

WithField creates an entry from the standard logger and adds a field to it.

func WithFields

func WithFields(fields Fields) *Entry

WithFields creates an entry from the standard logger and adds multiple fields to it.

func WithTime

func WithTime(t time.Time) *Entry

WithTime creates an entry from the standard logger with a specific time.

func (*Entry) Debug

func (entry *Entry) Debug(args ...interface{})

Debug logs a message at debug level.

func (*Entry) Debugf

func (entry *Entry) Debugf(format string, args ...interface{})

Debugf logs a message at debug level with formatting.

func (*Entry) Debugln

func (entry *Entry) Debugln(args ...interface{})

Debugln logs a message at debug level.

func (*Entry) Error

func (entry *Entry) Error(args ...interface{})

Error logs a message at error level.

func (*Entry) Errorf

func (entry *Entry) Errorf(format string, args ...interface{})

Errorf logs a message at error level with formatting.

func (*Entry) Errorln

func (entry *Entry) Errorln(args ...interface{})

Errorln logs a message at error level.

func (*Entry) Fatal

func (entry *Entry) Fatal(args ...interface{})

Fatal logs a message at fatal level and calls os.Exit(1).

func (*Entry) Fatalf

func (entry *Entry) Fatalf(format string, args ...interface{})

Fatalf logs a message at fatal level with formatting and calls os.Exit(1).

func (*Entry) Fatalln

func (entry *Entry) Fatalln(args ...interface{})

Fatalln logs a message at fatal level and calls os.Exit(1).

func (*Entry) Info

func (entry *Entry) Info(args ...interface{})

Info logs a message at info level.

func (*Entry) Infof

func (entry *Entry) Infof(format string, args ...interface{})

Infof logs a message at info level with formatting.

func (*Entry) Infoln

func (entry *Entry) Infoln(args ...interface{})

Infoln logs a message at info level.

func (*Entry) Panic

func (entry *Entry) Panic(args ...interface{})

Panic logs a message at panic level and panics.

func (*Entry) Panicf

func (entry *Entry) Panicf(format string, args ...interface{})

Panicf logs a message at panic level with formatting and panics.

func (*Entry) Panicln

func (entry *Entry) Panicln(args ...interface{})

Panicln logs a message at panic level and panics.

func (*Entry) Print

func (entry *Entry) Print(args ...interface{})

Print logs a message at info level.

func (*Entry) Printf

func (entry *Entry) Printf(format string, args ...interface{})

Printf logs a message at info level with formatting.

func (*Entry) Println

func (entry *Entry) Println(args ...interface{})

Println logs a message at info level.

func (*Entry) String

func (entry *Entry) String() string

String returns the string representation from the reader and ultimately the formatter.

func (*Entry) Trace

func (entry *Entry) Trace(args ...interface{})

Trace logs a message at trace level.

func (*Entry) Tracef

func (entry *Entry) Tracef(format string, args ...interface{})

Tracef logs a message at trace level with formatting.

func (*Entry) Traceln

func (entry *Entry) Traceln(args ...interface{})

Traceln logs a message at trace level.

func (*Entry) Warn

func (entry *Entry) Warn(args ...interface{})

Warn logs a message at warn level.

func (*Entry) Warnf

func (entry *Entry) Warnf(format string, args ...interface{})

Warnf logs a message at warn level with formatting.

func (*Entry) Warning

func (entry *Entry) Warning(args ...interface{})

Warning logs a message at warn level.

func (*Entry) Warningf

func (entry *Entry) Warningf(format string, args ...interface{})

Warningf logs a message at warn level with formatting.

func (*Entry) Warningln

func (entry *Entry) Warningln(args ...interface{})

Warningln logs a message at warn level.

func (*Entry) Warnln

func (entry *Entry) Warnln(args ...interface{})

Warnln logs a message at warn level.

func (*Entry) WithContext

func (entry *Entry) WithContext(ctx context.Context) *Entry

WithContext adds a context to the Entry.

func (*Entry) WithError

func (entry *Entry) WithError(err error) *Entry

WithError adds an error as single field to the Entry.

func (*Entry) WithField

func (entry *Entry) WithField(key string, value interface{}) *Entry

WithField allocates a new entry and adds a field to it.

func (*Entry) WithFields

func (entry *Entry) WithFields(fields Fields) *Entry

WithFields adds a map of fields to the Entry.

func (*Entry) WithTime

func (entry *Entry) WithTime(t time.Time) *Entry

WithTime overrides the time of the Entry.

type FieldMap

type FieldMap map[string]string

FieldMap allows customization of the key names for default fields.

type Fields

type Fields map[string]interface{}

Fields type for structured logging.

type Formatter

type Formatter interface {
	Format(*Entry) ([]byte, error)
}

Formatter interface defines how to format log entries.

type Hook

type Hook interface {
	Levels() []Level
	Fire(*Entry) error
}

Hook interface allows adding hooks to loggers.

type InteractiveMigration

type InteractiveMigration struct {
	// contains filtered or unexported fields
}

InteractiveMigration provides an interactive migration experience.

func NewInteractiveMigration

func NewInteractiveMigration(input io.Reader, output io.Writer) *InteractiveMigration

NewInteractiveMigration creates a new interactive migration helper.

func (*InteractiveMigration) RunInteractive

func (im *InteractiveMigration) RunInteractive() error

RunInteractive runs an interactive migration session.

type JSONFormatter

type JSONFormatter struct {
	TimestampFormat   string
	DisableTimestamp  bool
	DisableHTMLEscape bool
	DataKey           string
	FieldMap          FieldMap
	CallerPrettyfier  func(*runtime.Frame) (function string, file string)
	PrettyPrint       bool
}

JSONFormatter formats logs into parsable json.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(entry *Entry) ([]byte, error)

Format renders a single log entry.

type Level

type Level uint32

Level defines logging levels compatible with Logrus.

const (
	// PanicLevel level, highest level of severity.
	PanicLevel Level = iota
	// FatalLevel level. Logs and then calls `os.Exit(1)`.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's happening inside the application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging.
	DebugLevel
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
)

func AllLevels

func AllLevels() []Level

AllLevels returns all available log levels.

func GetLevel

func GetLevel() Level

GetLevel returns the standard logger level.

func ParseLevel

func ParseLevel(lvl string) (Level, error)

ParseLevel converts a string to a Level.

func (Level) String

func (l Level) String() string

String returns the string representation of the level.

type LevelHooks

type LevelHooks map[Level][]Hook

LevelHooks is a map of hooks for each level.

func (LevelHooks) Add

func (hooks LevelHooks) Add(hook Hook)

Add a hook to a level.

func (LevelHooks) Fire

func (hooks LevelHooks) Fire(level Level, entry *Entry) error

Fire all hooks for a level.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger provides a Logrus-compatible API backed by Bolt for easier migration.

func New

func New() *Logger

New creates a new Logrus-compatible logger backed by Bolt.

func (*Logger) AddHook

func (logger *Logger) AddHook(hook Hook)

AddHook adds a hook to the logger.

func (*Logger) Debug

func (logger *Logger) Debug(args ...interface{})

func (*Logger) Debugf

func (logger *Logger) Debugf(format string, args ...interface{})

func (*Logger) Debugln

func (logger *Logger) Debugln(args ...interface{})

func (*Logger) Error

func (logger *Logger) Error(args ...interface{})

func (*Logger) Errorf

func (logger *Logger) Errorf(format string, args ...interface{})

func (*Logger) Errorln

func (logger *Logger) Errorln(args ...interface{})

func (*Logger) Fatal

func (logger *Logger) Fatal(args ...interface{})

func (*Logger) Fatalf

func (logger *Logger) Fatalf(format string, args ...interface{})

func (*Logger) Fatalln

func (logger *Logger) Fatalln(args ...interface{})

func (*Logger) GetLevel

func (logger *Logger) GetLevel() Level

GetLevel returns the logger level.

func (*Logger) Info

func (logger *Logger) Info(args ...interface{})

func (*Logger) Infof

func (logger *Logger) Infof(format string, args ...interface{})

func (*Logger) Infoln

func (logger *Logger) Infoln(args ...interface{})

func (*Logger) IsLevelEnabled

func (logger *Logger) IsLevelEnabled(level Level) bool

IsLevelEnabled checks if the logger will output a logging event.

func (*Logger) Log

func (logger *Logger) Log(level Level, args ...interface{})

Log logs an entry.

func (*Logger) Logf

func (logger *Logger) Logf(level Level, format string, args ...interface{})

Logf logs a formatted entry.

func (*Logger) Logln

func (logger *Logger) Logln(level Level, args ...interface{})

Logln logs an entry with a newline.

func (*Logger) Panic

func (logger *Logger) Panic(args ...interface{})

func (*Logger) Panicf

func (logger *Logger) Panicf(format string, args ...interface{})

func (*Logger) Panicln

func (logger *Logger) Panicln(args ...interface{})

func (*Logger) Print

func (logger *Logger) Print(args ...interface{})

func (*Logger) Printf

func (logger *Logger) Printf(format string, args ...interface{})

func (*Logger) Println

func (logger *Logger) Println(args ...interface{})

func (*Logger) SetFormatter

func (logger *Logger) SetFormatter(formatter Formatter)

SetFormatter sets the logger formatter.

func (*Logger) SetLevel

func (logger *Logger) SetLevel(level Level)

SetLevel sets the logger level.

func (*Logger) SetOutput

func (logger *Logger) SetOutput(output io.Writer)

SetOutput sets the output destination.

func (*Logger) Trace

func (logger *Logger) Trace(args ...interface{})

Logging methods for each level

func (*Logger) Tracef

func (logger *Logger) Tracef(format string, args ...interface{})

Formatted logging methods

func (*Logger) Traceln

func (logger *Logger) Traceln(args ...interface{})

Line logging methods

func (*Logger) Warn

func (logger *Logger) Warn(args ...interface{})

func (*Logger) Warnf

func (logger *Logger) Warnf(format string, args ...interface{})

func (*Logger) Warning

func (logger *Logger) Warning(args ...interface{})

func (*Logger) Warningf

func (logger *Logger) Warningf(format string, args ...interface{})

func (*Logger) Warningln

func (logger *Logger) Warningln(args ...interface{})

func (*Logger) Warnln

func (logger *Logger) Warnln(args ...interface{})

func (*Logger) WithContext

func (logger *Logger) WithContext(ctx context.Context) *Entry

WithContext creates an entry with a context.

func (*Logger) WithError

func (logger *Logger) WithError(err error) *Entry

WithError creates an entry with an error field.

func (*Logger) WithField

func (logger *Logger) WithField(key string, value interface{}) *Entry

WithField allocates a new entry and adds a field to it.

func (*Logger) WithFields

func (logger *Logger) WithFields(fields Fields) *Entry

WithFields creates an entry with multiple fields.

func (*Logger) WithTime

func (logger *Logger) WithTime(t time.Time) *Entry

WithTime creates an entry with a specific time.

type LogrusTransformer

type LogrusTransformer struct {
	// contains filtered or unexported fields
}

LogrusTransformer handles the transformation of Logrus code to Bolt.

func NewLogrusTransformer

func NewLogrusTransformer() *LogrusTransformer

NewLogrusTransformer creates a new transformer for Logrus to Bolt migration.

func (*LogrusTransformer) GenerateMigrationReport

func (t *LogrusTransformer) GenerateMigrationReport(results []*TransformationResult, outputPath string) error

GenerateMigrationReport generates a comprehensive migration report.

func (*LogrusTransformer) TransformDirectory

func (t *LogrusTransformer) TransformDirectory(inputDir, outputDir string) ([]*TransformationResult, error)

TransformDirectory transforms all Go files in a directory.

func (*LogrusTransformer) TransformFile

func (t *LogrusTransformer) TransformFile(inputPath, outputPath string) (*TransformationResult, error)

TransformFile transforms a single file from Logrus to Bolt.

func (*LogrusTransformer) ValidateTransformation

func (t *LogrusTransformer) ValidateTransformation(inputPath, outputPath string) (*ValidationResult, error)

ValidateTransformation validates that the transformation was successful.

type PerformanceComparisonResult

type PerformanceComparisonResult struct {
	TestName          string  `json:"test_name"`
	LogrusNsPerOp     int64   `json:"logrus_ns_per_op"`
	BoltNsPerOp       int64   `json:"bolt_ns_per_op"`
	LogrusAllocsPerOp int64   `json:"logrus_allocs_per_op"`
	BoltAllocsPerOp   int64   `json:"bolt_allocs_per_op"`
	LogrusBytesPerOp  int64   `json:"logrus_bytes_per_op"`
	BoltBytesPerOp    int64   `json:"bolt_bytes_per_op"`
	SpeedImprovement  float64 `json:"speed_improvement_percent"`
	AllocImprovement  float64 `json:"alloc_improvement_percent"`
	MemoryImprovement float64 `json:"memory_improvement_percent"`
}

PerformanceComparisonResult holds the results of a performance comparison.

func RunPerformanceComparison

func RunPerformanceComparison() []PerformanceComparisonResult

RunPerformanceComparison runs a comprehensive performance comparison between Logrus and Bolt.

type TextFormatter

type TextFormatter struct {
	ForceColors               bool
	DisableColors             bool
	ForceQuote                bool
	DisableQuote              bool
	EnvironmentOverrideColors bool
	DisableTimestamp          bool
	FullTimestamp             bool
	TimestampFormat           string
	DisableSorting            bool
	SortingFunc               func([]string)
	DisableLevelTruncation    bool
	PadLevelText              bool
	QuoteEmptyFields          bool
	CallerPrettyfier          func(*runtime.Frame) (function string, file string)
}

TextFormatter formats logs into text.

func (*TextFormatter) Format

func (f *TextFormatter) Format(entry *Entry) ([]byte, error)

Format renders a single log entry.

type TransformationResult

type TransformationResult struct {
	OriginalFile    string         `json:"original_file"`
	TransformedFile string         `json:"transformed_file"`
	AppliedRules    []string       `json:"applied_rules"`
	Errors          []string       `json:"errors"`
	Warnings        []string       `json:"warnings"`
	LineChanges     map[int]string `json:"line_changes"`
	Success         bool           `json:"success"`
}

TransformationResult represents the result of a transformation operation.

type TransformationRule

type TransformationRule struct {
	Name        string
	Description string
	Pattern     *regexp.Regexp
	Replace     string
	IsRegex     bool
}

TransformationRule represents a rule for transforming Logrus code to Bolt.

type ValidationResult

type ValidationResult struct {
	Success  bool     `json:"success"`
	Errors   []string `json:"errors"`
	Warnings []string `json:"warnings"`
}

ValidationResult represents validation results.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL