Compare commits

...

5 Commits

Author SHA1 Message Date
h
90976ca98b Update hlog/README.md 2026-01-13 13:26:09 +11:00
h
328adaadee Merge pull request 'Updated hlog documentation to comply with GOLIB rules.' (#1) from hlogdoc into master
Reviewed-on: #1
2026-01-13 13:24:55 +11:00
h
5be9811afc Update hlog/README.md 2026-01-13 13:24:07 +11:00
52341aba56 Updated hlog documentation to comply with GOLIB rules.
- Added comprehensive README.md with proper format and version number
- Enhanced doc.go with complete godoc-compliant documentation
- Updated RULES.md to clarify wiki home page requirement

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 13:20:40 +11:00
7471ae881b updated RULES.md 2026-01-13 13:02:02 +11:00
3 changed files with 111 additions and 17 deletions

View File

@@ -8,7 +8,7 @@ Documentation is done in a few ways:
- wiki - wiki
The README for each module should be laid out as follows: The README for each module should be laid out as follows:
- Title and description - Title and description with version number
- Feature list (DO NOT USE EMOTICONS) - Feature list (DO NOT USE EMOTICONS)
- Installation (go get) - Installation (go get)
- Quick Start (brief example of setting up and using) - Quick Start (brief example of setting up and using)
@@ -24,7 +24,8 @@ Any Config structs with environment variables should have their docstrings match
where the required and default fields are only present if relevant to that variable where the required and default fields are only present if relevant to that variable
The wiki is located at ~/projects/golib-wiki and should be laid out as follows: The wiki is located at ~/projects/golib-wiki and should be laid out as follows:
- Title and description with version number (i will manually handle commits and versioning) - Link to wiki page from the Home page
- Title and description with version number
- Installation - Installation
- Key Concepts and features - Key Concepts and features
- Quick start - Quick start
@@ -39,5 +40,7 @@ The wiki is located at ~/projects/golib-wiki and should be laid out as follows:
2. All features should have tests. 2. All features should have tests.
Any changes to existing features or additional features implemented should have tests created and/or updated Any changes to existing features or additional features implemented should have tests created and/or updated
3. NEVER COMMIT 3. Version control
I will handle and manage all version control Version numbers are specified using git tags.
Do not change version numbers. When updating documentation, append the branch name to the version number.
Changes made to the golib-wiki repo should be made under the same branch name as the changes made in this repo

73
hlog/README.md Normal file
View File

@@ -0,0 +1,73 @@
# HLog - v0.10.2
A structured logging package for Go built on top of [zerolog](https://github.com/rs/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
```bash
go get git.haelnorr.com/h/golib/hlog
```
## Quick Start
```go
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](https://git.haelnorr.com/h/golib-wiki/HLog).
Additional API documentation is available at [GoDoc](https://pkg.go.dev/git.haelnorr.com/h/golib/hlog).
## 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.
## Related Projects
- [env](https://git.haelnorr.com/h/golib/env) - Environment variable helper used by hlog for configuration
- [zerolog](https://github.com/rs/zerolog) - The underlying logging library

View File

@@ -24,18 +24,22 @@
// //
// # Configuration // # Configuration
// //
// hlog can be configured via environment variables: // hlog can be configured via environment variables using ConfigFromEnv:
// //
// LOG_LEVEL=info # trace, debug, info, warn, error, fatal, panic (default: info) // LOG_LEVEL=info # trace, debug, info, warn, error, fatal, panic (default: info)
// LOG_OUTPUT=console # console, file, or both (default: console) // LOG_OUTPUT=console # console, file, or both (default: console)
// LOG_DIR=/var/log/app # Required when LOG_OUTPUT is "file" or "both" // LOG_DIR=/var/log/app # Required when LOG_OUTPUT is "file" or "both"
// LOG_FILE_NAME=server.log # Required when LOG_OUTPUT is "file" or "both"
// LOG_APPEND=true # Append to existing file or overwrite (default: true)
// //
// Or programmatically: // Or programmatically:
// //
// cfg := &hlog.Config{ // cfg := &hlog.Config{
// LogLevel: hlog.InfoLevel, // LogLevel: hlog.InfoLevel,
// LogOutput: "both", // LogOutput: "both",
// LogDir: "/var/log/myapp", // LogDir: "/var/log/myapp",
// LogFileName: "server.log",
// LogAppend: true,
// } // }
// //
// # Log Levels // # Log Levels
@@ -52,13 +56,27 @@
// # Output Modes // # Output Modes
// //
// - console: Logs to the provided io.Writer (typically os.Stdout or os.Stderr) // - console: Logs to the provided io.Writer (typically os.Stdout or os.Stderr)
// - file: Logs to a file named "server.log" in the configured directory // - file: Logs to a file in the configured directory
// - both: Logs to both console and file simultaneously // - both: Logs to both console and file simultaneously using zerolog.MultiLevelWriter
// //
// # File Management // # File Management
// //
// When using file output, hlog creates a file named "server.log" in the // When using file output, hlog creates a file with the specified name in the
// specified directory. The file is opened in append mode, so logs persist // configured directory. The file can be opened in append mode (default) to
// across application restarts. Remember to call CloseLogFile() when shutting // preserve logs across application restarts, or in overwrite mode to start
// down your application to ensure all logs are flushed. // fresh each time. Remember to call CloseLogFile() when shutting down your
// application to ensure all logs are flushed to disk.
//
// # Error Stack Traces
//
// hlog automatically configures zerolog to include stack traces for errors
// wrapped with github.com/pkg/errors. This provides detailed error context
// when using errors.Wrap or errors.WithStack.
//
// # Integration
//
// hlog integrates with:
// - git.haelnorr.com/h/golib/env: For environment variable configuration
// - github.com/rs/zerolog: The underlying logging implementation
// - github.com/pkg/errors: For error stack trace support
package hlog package hlog