stdlog

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: 16 Imported by: 0

Documentation

Overview

Package stdlog provides benchmarking tools for comparing standard log and Bolt performance.

Package stdlog provides compatibility layer and migration tools for Go standard log users.

Package stdlog provides examples demonstrating migration from Go's standard log to Bolt.

Package stdlog provides code transformation tools for migrating from standard log to Bolt.

Index

Constants

View Source
const (
	Ldate         = 1 << iota     // the date in the local time zone
	Ltime                         // the time in the local time zone
	Lmicroseconds                 // microsecond resolution
	Llongfile                     // full file name and line number
	Lshortfile                    // final file name element and line number
	LUTC                          // use UTC rather than the local time zone
	Lmsgprefix                    // move the "prefix" from the beginning of the line to before the message
	LstdFlags     = Ldate | Ltime // initial values for the standard logger
)

Log flag constants - compatible with standard library log package.

Variables

This section is empty.

Functions

func BenchmarkBoltComplexStructured

func BenchmarkBoltComplexStructured(b *testing.B)

BenchmarkBoltComplexStructured benchmarks equivalent complex structured logging.

func BenchmarkBoltContextualLogger

func BenchmarkBoltContextualLogger(b *testing.B)

BenchmarkBoltContextualLogger benchmarks Bolt with contextual logging.

func BenchmarkBoltSimpleLogging

func BenchmarkBoltSimpleLogging(b *testing.B)

BenchmarkBoltSimpleLogging benchmarks equivalent Bolt logging.

func BenchmarkBoltStructuredLogging

func BenchmarkBoltStructuredLogging(b *testing.B)

BenchmarkBoltStructuredLogging benchmarks equivalent structured Bolt logging.

func BenchmarkBoltWithCallerInfo

func BenchmarkBoltWithCallerInfo(b *testing.B)

BenchmarkBoltWithCallerInfo benchmarks Bolt logging with caller info.

func BenchmarkStandardLogCompatibility

func BenchmarkStandardLogCompatibility(b *testing.B)

BenchmarkStandardLogCompatibility benchmarks the compatibility layer.

func BenchmarkStandardLogComplexFormatting

func BenchmarkStandardLogComplexFormatting(b *testing.B)

BenchmarkStandardLogComplexFormatting benchmarks complex string formatting.

func BenchmarkStandardLogCustomLogger

func BenchmarkStandardLogCustomLogger(b *testing.B)

BenchmarkStandardLogCustomLogger benchmarks custom logger usage.

func BenchmarkStandardLogPrint

func BenchmarkStandardLogPrint(b *testing.B)

BenchmarkStandardLogPrint benchmarks standard library log.Print.

func BenchmarkStandardLogPrintf

func BenchmarkStandardLogPrintf(b *testing.B)

BenchmarkStandardLogPrintf benchmarks standard library log.Printf.

func BenchmarkStandardLogWithCallerInfo

func BenchmarkStandardLogWithCallerInfo(b *testing.B)

BenchmarkStandardLogWithCallerInfo benchmarks standard log with caller info.

func ConcurrentBenchmark

func ConcurrentBenchmark()

ConcurrentBenchmark demonstrates concurrent logging performance.

func Debug

func Debug(v ...interface{})

Debug provides debug-level logging (not in standard log, but commonly needed).

func Debugf

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

Debugf provides formatted debug-level logging.

func EnableStructuredLogging

func EnableStructuredLogging() *bolt.Logger

EnableStructuredLogging enables structured logging features while maintaining compatibility. This allows gradual migration to structured logging patterns.

func Error

func Error(v ...interface{})

Error provides error-level logging.

func Errorf

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

Errorf provides formatted error-level logging.

func ExampleAdvancedFeatures

func ExampleAdvancedFeatures()

ExampleAdvancedFeatures demonstrates advanced Bolt features not available in standard log.

func ExampleBasicMigration

func ExampleBasicMigration()

ExampleBasicMigration demonstrates basic logging migration from standard log to Bolt.

func ExampleConfigurationMigration

func ExampleConfigurationMigration()

ExampleConfigurationMigration demonstrates configuration migration patterns.

func ExampleCustomLogger

func ExampleCustomLogger()

ExampleCustomLogger demonstrates custom logger migration.

func ExampleDropInReplacement

func ExampleDropInReplacement()

ExampleDropInReplacement demonstrates the drop-in replacement approach.

func ExampleErrorHandling

func ExampleErrorHandling()

ExampleErrorHandling demonstrates error and panic handling migration.

func ExampleGradualMigration

func ExampleGradualMigration()

ExampleGradualMigration demonstrates a step-by-step migration approach.

func ExampleLogLevels

func ExampleLogLevels()

ExampleLogLevels demonstrates migrating from print statements to proper levels.

func ExampleMigrationBestPractices

func ExampleMigrationBestPractices()

ExampleMigrationBestPractices demonstrates best practices during and after migration.

func ExampleMigrationStrategies

func ExampleMigrationStrategies()

ExampleMigrationStrategies demonstrates different migration approaches.

func ExampleOutputFormats

func ExampleOutputFormats()

ExampleOutputFormats demonstrates different output format options.

func ExamplePerformanceComparison

func ExamplePerformanceComparison()

ExamplePerformanceComparison demonstrates performance benefits.

func ExamplePerformanceTesting

func ExamplePerformanceTesting()

ExamplePerformanceTesting demonstrates how to measure migration benefits.

func ExampleRealWorldMigration

func ExampleRealWorldMigration()

ExampleRealWorldMigration demonstrates a complete real-world migration scenario.

func ExampleStructuredLogging

func ExampleStructuredLogging()

ExampleStructuredLogging demonstrates the evolution from string formatting to structured fields.

func ExampleTestingMigration

func ExampleTestingMigration()

ExampleTestingMigration demonstrates testing considerations during migration.

func Fatal

func Fatal(v ...interface{})

Fatal is equivalent to Print() followed by a call to os.Exit(1).

func Fatalf

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

Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

func Fatalln

func Fatalln(v ...interface{})

Fatalln is equivalent to Println() followed by a call to os.Exit(1).

func Flags

func Flags() int

Flags returns the output flags for the standard logger.

func GetUnderlyingLogger

func GetUnderlyingLogger() *bolt.Logger

GetUnderlyingLogger returns the underlying Bolt logger for advanced usage. This allows access to Bolt's structured logging features while maintaining standard log compatibility for the rest of the application.

func Info

func Info(v ...interface{})

Info provides info-level logging (alias for Print functions).

func Infof

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

Infof provides formatted info-level logging (alias for Printf).

func MemoryProfileComparison

func MemoryProfileComparison()

MemoryProfileComparison demonstrates memory usage patterns.

func MigrateStandardLogger

func MigrateStandardLogger(output io.Writer, prefix string, flag int)

MigrateStandardLogger replaces the global standard logger with a Bolt-backed version. This is useful for applications that use the global log functions.

func Output

func Output(calldepth int, s string) error

Output writes the output for a logging event. The string s contains the text to print; a newline character will be added if one is not provided. Calldepth is used to recover the PC and is provided for generality, although at the moment on all pre-defined paths it will be 2.

func Panic

func Panic(v ...interface{})

Panic is equivalent to Print() followed by a call to panic().

func Panicf

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

Panicf is equivalent to Printf() followed by a call to panic().

func Panicln

func Panicln(v ...interface{})

Panicln is equivalent to Println() followed by a call to panic().

func Prefix

func Prefix() string

Prefix returns the output prefix for the standard logger.

func Print

func Print(v ...interface{})

Print calls Output to print to the standard logger.

func PrintMigrationImpactReport

func PrintMigrationImpactReport(reports []MigrationImpactReport)

PrintMigrationImpactReport prints the business impact of migration.

func PrintPerformanceReport

func PrintPerformanceReport(metrics []PerformanceMetrics)

PrintPerformanceReport prints a detailed performance comparison report.

func Printf

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

Printf calls Output to print to the standard logger.

func Println

func Println(v ...interface{})

Println calls Output to print to the standard logger.

func SetFlags

func SetFlags(flag int)

SetFlags sets the output flags for the standard logger.

func SetLevel

func SetLevel(level string)

SetLevel sets the logging level for the underlying Bolt logger. This provides level-based filtering not available in standard log.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the standard logger.

func SetPrefix

func SetPrefix(prefix string)

SetPrefix sets the output prefix for the standard logger.

func Warn

func Warn(v ...interface{})

Warn provides warning-level logging.

func Warnf

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

Warnf provides formatted warning-level logging.

func Writer

func Writer() io.Writer

Writer returns the output destination for the standard logger.

Types

type BenchmarkReport

type BenchmarkReport struct {
	Timestamp        string                  `json:"timestamp"`
	Summary          BenchmarkSummary        `json:"summary"`
	PerformanceTests []PerformanceMetrics    `json:"performance_tests"`
	ImpactAnalysis   []MigrationImpactReport `json:"impact_analysis"`
	Recommendations  []string                `json:"recommendations"`
}

BenchmarkReport provides a comprehensive benchmark report.

func GenerateComprehensiveBenchmarkReport

func GenerateComprehensiveBenchmarkReport() *BenchmarkReport

GenerateComprehensiveBenchmarkReport creates a full benchmark report.

type BenchmarkSummary

type BenchmarkSummary struct {
	TotalTests              int     `json:"total_tests"`
	AverageSpeedImprovement float64 `json:"average_speed_improvement"`
	AverageAllocReduction   float64 `json:"average_alloc_reduction"`
	AverageMemoryReduction  float64 `json:"average_memory_reduction"`
	MaxSpeedImprovement     float64 `json:"max_speed_improvement"`
	MinSpeedImprovement     float64 `json:"min_speed_improvement"`
	RecommendedMigration    string  `json:"recommended_migration"`
}

BenchmarkSummary provides overall benchmark statistics.

type InteractiveMigration

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

InteractiveMigration provides interactive migration for standard log.

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 Logger

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

Logger provides a drop-in replacement for Go's standard log.Logger. This allows existing code using the standard library to benefit from Bolt's performance while maintaining full API compatibility.

func CreateCompatibleLogger

func CreateCompatibleLogger(output io.Writer) *Logger

CreateCompatibleLogger creates a logger that's compatible with existing standard log usage but provides the performance benefits of Bolt.

func Default

func Default() *Logger

Default creates a standard logger that writes to stderr with default flags.

func New

func New(out io.Writer, prefix string, flag int) *Logger

New creates a new Logger that's compatible with Go's standard log.Logger. The out parameter is the destination to which log data will be written. The prefix appears at the beginning of each generated log line, or after the log header if Lmsgprefix flag is provided. The flag argument defines the logging properties.

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

Fatal is equivalent to Print() followed by a call to os.Exit(1).

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

func (*Logger) Fatalln

func (l *Logger) Fatalln(v ...interface{})

Fatalln is equivalent to Println() followed by a call to os.Exit(1).

func (*Logger) Flags

func (l *Logger) Flags() int

Flags returns the output flags for the logger.

func (*Logger) Output

func (l *Logger) Output(calldepth int, s string) error

Output writes the output for a logging event. The calldepth parameter is ignored as Bolt handles caller information automatically.

func (*Logger) Panic

func (l *Logger) Panic(v ...interface{})

Panic is equivalent to Print() followed by a call to panic().

func (*Logger) Panicf

func (l *Logger) Panicf(format string, v ...interface{})

Panicf is equivalent to Printf() followed by a call to panic().

func (*Logger) Panicln

func (l *Logger) Panicln(v ...interface{})

Panicln is equivalent to Println() followed by a call to panic().

func (*Logger) Prefix

func (l *Logger) Prefix() string

Prefix returns the output prefix for the logger.

func (*Logger) Print

func (l *Logger) Print(v ...interface{})

Print calls l.Output to print to the logger.

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

Printf calls l.Output to print to the logger.

func (*Logger) Println

func (l *Logger) Println(v ...interface{})

Println calls l.Output to print to the logger.

func (*Logger) SetFlags

func (l *Logger) SetFlags(flag int)

SetFlags sets the output flags for the logger.

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

SetOutput sets the output destination for the logger.

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(prefix string)

SetPrefix sets the output prefix for the logger.

func (*Logger) Writer

func (l *Logger) Writer() io.Writer

Writer returns the output destination for the logger.

type MigrationImpactReport

type MigrationImpactReport struct {
	ApplicationScenario   string  `json:"application_scenario"`
	LogsPerSecond         int     `json:"logs_per_second"`
	StandardLogLatency    float64 `json:"standard_log_latency_ns"`
	BoltLatency           float64 `json:"bolt_latency_ns"`
	LatencyReduction      float64 `json:"latency_reduction_percent"`
	ThroughputImprovement float64 `json:"throughput_improvement_percent"`
	MemoryReduction       float64 `json:"memory_reduction_percent"`
	CPUReduction          float64 `json:"cpu_reduction_percent"`
}

MigrationImpactReport demonstrates the business impact of migration.

func GenerateMigrationImpactReport

func GenerateMigrationImpactReport() []MigrationImpactReport

GenerateMigrationImpactReport creates impact reports for different scenarios.

type PerformanceMetrics

type PerformanceMetrics struct {
	TestName                string  `json:"test_name"`
	StandardLogNsPerOp      int64   `json:"standard_log_ns_per_op"`
	BoltNsPerOp             int64   `json:"bolt_ns_per_op"`
	StandardLogAllocsPerOp  int64   `json:"standard_log_allocs_per_op"`
	BoltAllocsPerOp         int64   `json:"bolt_allocs_per_op"`
	StandardLogBytesPerOp   int64   `json:"standard_log_bytes_per_op"`
	BoltBytesPerOp          int64   `json:"bolt_bytes_per_op"`
	SpeedImprovementPercent float64 `json:"speed_improvement_percent"`
	AllocReductionPercent   float64 `json:"alloc_reduction_percent"`
	MemoryReductionPercent  float64 `json:"memory_reduction_percent"`
}

PerformanceMetrics holds performance comparison results.

func RunPerformanceComparison

func RunPerformanceComparison() []PerformanceMetrics

RunPerformanceComparison runs a comprehensive performance comparison.

type StdlogTransformer

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

StdlogTransformer handles the transformation of standard log code to Bolt.

func NewStdlogTransformer

func NewStdlogTransformer() *StdlogTransformer

NewStdlogTransformer creates a new transformer for standard log to Bolt migration.

func (*StdlogTransformer) GenerateMigrationGuide

func (t *StdlogTransformer) GenerateMigrationGuide(results []*TransformationResult, outputPath string) error

GenerateMigrationGuide generates a comprehensive migration guide.

func (*StdlogTransformer) TransformDirectory

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

TransformDirectory transforms all Go files in a directory.

func (*StdlogTransformer) TransformFile

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

TransformFile transforms a single file from standard log to Bolt.

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"`
	RequiresManual  []string       `json:"requires_manual"`
}

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 standard log code to Bolt.

Jump to

Keyboard shortcuts

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