A simple, flexible, and thread-safe logging system for Go applications.
- Thread-safe logging with mutex protection
- Multiple log levels (Debug, Info, Warn, Error, Event)
- Customizable minimum log level
- Colored terminal output (optional)
- Custom timestamp formatting
- Standard library compatibility through
log.Logger
adapter
go get github.com/NodePassProject/logs
package main
import (
"github.com/NodePassProject/logs"
)
func main() {
// Create a new logger with INFO minimum level and color enabled
logger := logs.NewLogger(logs.Info, true)
// Log messages at different levels
logger.Debug("This debug message won't be shown because minimum level is INFO")
logger.Info("System started successfully")
logger.Warn("Configuration file not found, using defaults")
logger.Error("Failed to connect to database: %s", "connection timeout")
logger.Event("System event: application state changed")
}
// Create logger with INFO level
logger := logs.NewLogger(logs.Info, true)
// Later change to DEBUG level
logger.SetLogLevel(logs.Debug)
// Get current log level
currentLevel := logger.GetLogLevel()
logger := logs.NewLogger(logs.Info, true)
// Disable colored output
logger.EnableColor(false)
logger := logs.NewLogger(logs.Info, true)
// Get a standard library logger that uses our custom logger
stdLogger := logger.StdLogger()
// Use standard logger methods
stdLogger.Println("This message will be logged through our custom logger")
stdLogger.Printf("Formatted %s", "message")
Copyright (c) 2025, NodePassProject. Licensed under the BSD 3-Clause License. See the LICENSE file for details.