17 Commits

Author SHA1 Message Date
1884e07378 Make the README a little more concise. 2025-07-06 04:23:27 -05:00
2f761833bd Use message for structures message contents, not msg.
I like `msg`, but `message` is more common and likely to the more
expected name.
2025-07-06 04:12:47 -05:00
c4074007b5 Tweaks to README intro. 2025-07-06 04:12:23 -05:00
05f5c2548c Further edits to README, docs for appender implementations. 2025-07-06 03:25:01 -05:00
9861a93ee4 Add autoconfigured, multithreaded example to README. 2025-07-06 02:29:39 -05:00
4a8365ebef Update README for 2.0.0. 2025-07-06 02:17:25 -05:00
f80e5807db refactor: Complete rewrite of logging system with thread-safe architecture
This commit represents a complete architectural overhaul of the namespaced
logging library, transitioning from a shared-memory approach to a robust
thread-safe design with proper synchronization primitives.

- **NEW**: internal `GlobalLogService` with atomic configuration versioning
- **NEW**: Thread-local configuration caching with freshness checking
- **NEW**: Separate `LogService` (copyable) and `ThreadLocalLogService` (ref)
- **REMOVED**: Manual thread state reloading in favor of automatic freshness

- All shared state protected by locks and atomics
- Configuration changes use atomic version numbers for efficient sync
- Proper cleanup with `=destroy` implementing graceful shutdown
- Thread-safe appender cloning via `clone()` method pattern

- **NEW**: Dedicated writer threads for console and file output
- **NEW**: Channel-based message passing to writer threads
- **NEW**: Batched file I/O with optimized write patterns
- **NEW**: Graceful thread shutdown on service destruction

- **NEW**: Configurable error handling with `ErrorHandlerFunc`
- **NEW**: `defaultErrorHandlerFunc` with stderr fallback
- **NEW**: Thread-safe error reporting with separate lock
- **NEW**: Robust error recovery in all I/O operations

- **NEW**: `autoconfigured` module for zero-config usage
- **NEW**: `formatSimpleTextLog` as default formatter
- **NEW**: Optional logger support for ergonomic usage
- **NEW**: Generic `CustomLogAppender[T]` with state parameter
- **NEW**: `FileLogAppender` with proper multithreaded file I/O
- **BREAKING**: Logger `name` field renamed to `scope`
- **BREAKING**: Configuration methods renamed (e.g., `setRootLevel` → `setRootThreshold`)

- **NEW**: Comprehensive test suite with 20+ test cases
- **NEW**: `testutil` module with thread-safe test infrastructure
- **NEW**: Cross-thread synchronization testing
- **NEW**: File I/O testing with temporary files
- **REMOVED**: Old test suite replaced with more comprehensive version

- Atomic version checking prevents unnecessary config copies
- Writer threads use efficient polling with 100ms idle sleep
- File writer batches messages and optimizes file operations
- Thread-local caching reduces lock contention

1. **API Changes**:
   - `LogService` returned by `iniLogService` is fundamentally different
   - `threadLocalRef()` required for thread-local operations
   - `reloadThreadState()` removed (automatic freshness)
   - Logger field `name` → `scope`

2. **Configuration**:
   - `setRootLevel()` → `setRootThreshold()`
   - `setThreshold()` API simplified
   - `clearAppenders()` removed

3. **Appenders**:
   - `initThreadCopy()` → `clone()`
   - `appendLogMessage()` signature changed
   - Custom appenders now generic with state parameter

```nim
let ls = initLogService()
ls.addAppender(initConsoleLogAppender())
reloadThreadState(ls)
let logger = ls.getLogger("app")
logger.info("Hello world")
```

```nim
let ls = initLogService()
let tlls = threadLocalRef(ls)
tlls.addAppender(initConsoleLogAppender())
let logger = tlls.getLogger("app")
logger.info("Hello world")
```
```nim
import namespaced_logging/autoconfigured
addLogAppender(initConsoleLogAppender())
info("Hello world")
```
2.0.0
2025-07-06 01:03:35 -05:00
e0dba8125c Add CustomLogAppender to allow extensible log appenders. 1.1.0 2025-05-19 18:05:06 -05:00
0eb0d33573 Expose appender config, default ConsoleLogAppender threshold to ALL. 1.0.1 2025-02-04 17:56:01 -06:00
92c2dec54d Major refactor to better support multi-threading.
See README for details.
1.0.0
2025-01-05 06:25:35 -06:00
ab20a30434 Swallow impossible exception. 0.3.2 2023-02-25 14:45:05 -07:00
f3dbac0896 Fix default prefix format. 0.3.1 2022-11-03 15:14:43 -05:00
c0f818ef30 setLevelForNamespace now instantiates the namespace if necessary
- Hide initLoggingNamespace. getLoggerForNamespace should be used
  instead.
- setLevelForNamespace now calls getLoggerForNamespace to ensure the
  namespace exists when a caller tries to set the logging level.
  Previously it was possible to call setLevelForNamespace before the
  namespace was initialized, meaning that the setting had no effect.
  This is especially problematic for cases where a library is using
  namespaced logging with the filter set to a high level by default.
  The code using that library may want to enable debug logs, and is
  likely to call setLevelForNamespace in initialization code that runs
  prior to the library code which instantiates the namespace.
0.3.0
2022-11-03 15:03:48 -05:00
8245cfbdf7 Use a table for thread-global cache, hierarchical logging namespaces. 0.2.0 2022-06-04 21:48:25 -05:00
79c3701f26 Add thread-global cache of namespaces, change default formatting. 0.1.0 2022-01-13 17:29:56 -06:00
5f21b2f263 Initial implementation. 2022-01-13 14:12:10 -06:00
3222260baa Initial commit following nimble init. 2022-01-13 13:22:13 -06:00