e3.2.0 File and console output clarity and uniform configuration, minor cleanup.

This commit is contained in:
2025-09-29 10:53:47 -04:00
parent d58b61067f
commit 162541e53f
13 changed files with 73 additions and 101 deletions

View File

@ -286,7 +286,7 @@ builder := compat.NewBuilder().
"format=txt", // Human-readable
"level=-4", // Debug level
"trace_depth=3", // Include traces
"enable_console=true", // Console output
"enable_console=true", // Console output
"flush_interval_ms=50", // Quick feedback
)
```
@ -296,8 +296,8 @@ builder := compat.NewBuilder().
```go
builder := compat.NewBuilder().
WithOptions(
"disable_file=true", // No files
"enable_console=true", // Console only
"enable_file=false", // No files
"enable_console=true", // Console only
"format=json", // For aggregators
"level=0", // Info and above
)

View File

@ -20,17 +20,17 @@ All builder methods return `*ConfigBuilder` for chaining. Errors are accumulated
### Common Methods
| Method | Parameters | Description |
|--------|------------|-------------|
| `Level(level int64)` | `level`: Numeric log level | Sets log level (-4 to 8) |
| `LevelString(level string)` | `level`: Named level | Sets level by name ("debug", "info", etc.) |
| `Directory(dir string)` | `dir`: Path | Sets log directory |
| `Format(format string)` | `format`: Output format | Sets format ("txt", "json", "raw") |
| `BufferSize(size int64)` | `size`: Buffer size | Sets channel buffer size |
| `MaxSizeKB(size int64)` | `size`: Size in MB | Sets max file size |
| `EnableConsole(enable bool)` | `enable`: Boolean | Enables console output |
| `DisableFile(disable bool)` | `disable`: Boolean | Disables file output |
| `HeartbeatLevel(level int64)` | `level`: 0-3 | Sets monitoring level |
| Method | Parameters | Description |
|-------------------------------|----------------------------|--------------------------------------------|
| `Level(level int64)` | `level`: Numeric log level | Sets log level (-4 to 8) |
| `LevelString(level string)` | `level`: Named level | Sets level by name ("debug", "info", etc.) |
| `Directory(dir string)` | `dir`: Path | Sets log directory |
| `Format(format string)` | `format`: Output format | Sets format ("txt", "json", "raw") |
| `BufferSize(size int64)` | `size`: Buffer size | Sets channel buffer size |
| `MaxSizeKB(size int64)` | `size`: Size in MB | Sets max file size |
| `EnableConsole(enable bool)` | `enable`: Boolean | Enables console output |
| `EnableFile(enable bool)` | `enable`: Boolean | Enable file output |
| `HeartbeatLevel(level int64)` | `level`: 0-3 | Sets monitoring level |
## Build

View File

@ -56,13 +56,13 @@ logger.Info("info txt log record written to /var/log/myapp.txt")
### Output Control
| Parameter | Type | Description | Default |
|-----------|------|-------------|---------|
| `show_timestamp` | `bool` | Include timestamps in log entries | `true` |
| `show_level` | `bool` | Include log level in entries | `true` |
| `enable_console` | `bool` | Mirror logs to stdout/stderr | `false` |
| Parameter | Type | Description | Default |
|------------------|------|------------------------------------------------------|------------|
| `show_timestamp` | `bool` | Include timestamps in log entries | `true` |
| `show_level` | `bool` | Include log level in entries | `true` |
| `enable_console` | `bool` | Enable console output (stdout/stderr) | `true` |
| `console_target` | `string` | Console target: `"stdout"`, `"stderr"`, or `"split"` | `"stdout"` |
| `disable_file` | `bool` | Disable file output (console-only) | `false` |
| `enable_file` | `bool` | Enable file output (console-only) | `true` |
**Note:** When `console_target="split"`, INFO/DEBUG logs go to stdout while WARN/ERROR logs go to stderr.

View File

@ -29,7 +29,7 @@ import (
func main() {
// Create a new logger instance with default configuration
// Writes to file ./log/log.log
// Writes to both console (stdout) and file ./log/log.log
logger := log.NewLogger()
defer logger.Shutdown()

View File

@ -135,6 +135,8 @@ Default format for development and debugging:
2024-01-15T10:30:45.234567890Z WARN Rate limit approaching user_id=42 requests=95 limit=100
```
Note: The text format does not add quotes around string values containing spaces. This ensures predictability for simple, space-delimited parsing tools. For logs where maintaining the integrity of such values is critical, `json` format is recommended.
Configuration:
```go
logger.ApplyConfigString(