feat: Add preprocessors and postprocessors for configurable log transformation#7
Open
feat: Add preprocessors and postprocessors for configurable log transformation#7
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #6
…formation
This commit implements a flexible preprocessor and postprocessor system that allows users to transform log arguments and messages without compromising performance.
Key features:
- Preprocessors: Transform arguments before processing (receive args array, return args array)
- Postprocessors: Transform compiled messages before output (receive string, return string)
- Built-in preprocessor helpers: addContext, filter, map
- Built-in postprocessor helpers: timestamp, level, pid, prefix, suffix
- Zero-overhead implementation when no processors configured
- Full TypeScript support
- Comprehensive test coverage (28 new tests)
The implementation ensures maximum efficiency:
- When no preprocessors/postprocessors are configured, the code path is identical to the original
- Processors only execute when the log level is enabled
- Lazy evaluation is preserved throughout the pipeline
Examples:
- Add timestamps: postprocessors: [postprocessors.timestamp('iso')]
- Add log levels: postprocessors: [postprocessors.level()]
- Filter sensitive data: preprocessors: [preprocessors.filter(arg => !arg.password)]
- Combine multiple: postprocessors: [level(), timestamp(), prefix('[App]')]
Fixes #6
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This reverts commit 12d6e9a.
Member
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a flexible preprocessor and postprocessor system that allows users to transform log arguments and messages without compromising the library's core performance characteristics.
Fixes #6
Key Features
Preprocessors
addContext,filter,mapPostprocessors
timestamp,level,pid,prefix,suffixZero-Overhead Design
Usage Examples
Adding Timestamps
Adding Log Levels
Combining Multiple Postprocessors
Filtering Sensitive Data with Preprocessors
Custom Processors
Implementation Details
Architecture
Performance Characteristics
Code Quality
Files Changed
Core Implementation
src/index.js: Added preprocessor/postprocessor logic with zero-overhead optimizationindex.d.ts: TypeScript definitions for new featuresTests
tests/preprocessors-postprocessors.test.js: 28 comprehensive tests covering:Examples & Experiments
examples/custom-processors.js: Real-world usage examplesexperiments/preprocessors-postprocessors.js: 11 experiments demonstrating various use casesDocumentation
CHANGELOG.md: Updated with new featuresTesting
All tests pass successfully:
Migration Guide
This is a non-breaking change. Existing code continues to work exactly as before:
🤖 Generated with Claude Code