1.9 KiB
1.9 KiB
HLog - v0.10.2
A structured logging package for Go built on top of zerolog. HLog provides simple configuration via environment variables, flexible output options, and automatic log file management.
Features
- Multiple output modes: console, file, or both simultaneously
- Configurable log levels: trace, debug, info, warn, error, fatal, panic
- Environment variable-based configuration with ConfigFromEnv
- Automatic log file management with append or overwrite modes
- Built on zerolog for high performance and structured logging
- Error stack trace support via pkg/errors integration
- Unix timestamp format
- Console-friendly output formatting
- Multi-writer support for simultaneous console and file output
Installation
go get git.haelnorr.com/h/golib/hlog
Quick Start
package main
import (
"log"
"os"
"git.haelnorr.com/h/golib/hlog"
)
func main() {
// Load configuration from environment variables
cfg, err := hlog.ConfigFromEnv()
if err != nil {
log.Fatal(err)
}
// Create a new logger
logger, err := hlog.NewLogger(cfg, os.Stdout)
if err != nil {
log.Fatal(err)
}
defer logger.CloseLogFile()
// Start logging
logger.Info().Msg("Application started")
logger.Debug().Str("user", "john").Msg("User logged in")
logger.Error().Err(err).Msg("Something went wrong")
}
Documentation
For detailed documentation, see the HLog Wiki.
Additional API documentation is available at GoDoc.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.