Skip to content

lazygophers/log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

lazygophers/log

Go Version Test Coverage Go Report Card License: MIT

A high-performance, flexible Go logging library built on zap, providing rich features and a simple API.

๐Ÿ“– Documentation Languages

๐Ÿš€ Online Documentation

Visit our GitHub Pages documentation for a better reading experience.

โœจ Features

  • ๐Ÿš€ High Performance: Built on zap with object pooling and conditional field recording
  • ๐Ÿ“Š Rich Log Levels: Trace, Debug, Info, Warn, Error, Fatal, Panic levels
  • โš™๏ธ Flexible Configuration:
    • Log level control
    • Caller information recording
    • Trace information (including goroutine ID)
    • Custom log prefixes and suffixes
    • Custom output targets (console, files, etc.)
    • Log formatting options
  • ๐Ÿ”„ File Rotation: Hourly log file rotation support
  • ๐Ÿ”Œ Zap Compatibility: Seamless integration with zap WriteSyncer
  • ๐ŸŽฏ Simple API: Clean API similar to standard log library, easy to use

๐Ÿš€ Quick Start

Installation

go get github.com/lazygophers/log

Basic Usage

package main

import (
    "github.com/lazygophers/log"
)

func main() {
    // Use default global logger
    log.Debug("Debug message")
    log.Info("Info message")
    log.Warn("Warning message")
    log.Error("Error message")

    // Use formatted output
    log.Infof("User %s logged in successfully", "admin")

    // Custom configuration
    customLogger := log.New().
        SetLevel(log.InfoLevel).
        EnableCaller(false).
        SetPrefixMsg("[MyApp]")

    customLogger.Info("This is a log from custom logger")
}

๐Ÿ“š Advanced Usage

Custom Logger with File Output

package main

import (
    "os"
    "github.com/lazygophers/log"
)

func main() {
    // Create logger with file output
    logger := log.New().
        SetLevel(log.DebugLevel).
        EnableCaller(true).
        EnableTrace(true).
        SetOutput(os.Stdout, log.GetOutputWriterHourly("/var/log/myapp.log"))

    logger.Debug("Debug message with caller info")
    logger.Info("Info message with trace info")
}

Log Level Control

package main

import "github.com/lazygophers/log"

func main() {
    logger := log.New().SetLevel(log.WarnLevel)

    // Only warn and above will be logged
    logger.Debug("This won't be logged")  // Ignored
    logger.Info("This won't be logged")   // Ignored
    logger.Warn("This will be logged")    // Logged
    logger.Error("This will be logged")   // Logged
}

๐Ÿ”ง Configuration Options

Logger Configuration

Method Description Default
SetLevel(level) Set minimum log level DebugLevel
EnableCaller(enable) Enable/disable caller info false
EnableTrace(enable) Enable/disable trace info false
SetCallerDepth(depth) Set caller depth 2
SetPrefixMsg(prefix) Set log prefix ""
SetSuffixMsg(suffix) Set log suffix ""
SetOutput(writers...) Set output targets os.Stdout

Log Levels

Level Description
TraceLevel Most verbose, for detailed tracing
DebugLevel Debug information
InfoLevel General information
WarnLevel Warning messages
ErrorLevel Error messages
FatalLevel Fatal errors (calls os.Exit(1))
PanicLevel Panic errors (calls panic())

๐Ÿ—๏ธ Architecture

Core Components

  • Logger: Main logging structure with configurable options
  • Entry: Individual log record with comprehensive field support
  • Level: Log level definitions and utility functions
  • Format: Log formatting interface and implementations

Performance Optimization

  • Object Pooling: Reuses Entry objects to reduce memory allocation
  • Conditional Recording: Only records expensive fields when needed
  • Fast Level Checking: Checks log level at the outermost layer
  • Lock-Free Design: Most operations don't require locks

๐Ÿ“Š Performance Comparison

Feature lazygophers/log zap logrus standard log
Performance High High Medium Low
API Simplicity High Medium High High
Feature Richness Medium High High Low
Flexibility Medium High High Low
Learning Curve Low Medium Medium Low

๐Ÿ”— Related Documentation

๐Ÿš€ Getting Help

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐ŸŒ Multilingual Documentation

This document is available in multiple languages:

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.


lazygophers/log is designed to be the go-to logging solution for Go developers who value both performance and simplicity. Whether you're building a small utility or a large-scale distributed system, this library provides the right balance of features and ease of use.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •