Add Support for Customizing Log Elements While Keeping Log Levels Mandatory #20
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 customizable log elements functionality, allowing users to control which components are included in log output while maintaining log levels as mandatory elements. This addresses the need for flexible log formatting in different deployment environments while preserving essential debugging information.
Key Features
✅ Customizable Timestamp Elements: Users can now control ISO timestamp and local time inclusion
✅ Mandatory Log Levels: Log levels always remain visible regardless of configuration (as required)
✅ Backward Compatible: Default behavior unchanged - existing code works without modifications
✅ Type Safe: Full TypeScript support with new
LogFormatConfig
interface✅ Comprehensive Testing: 17 new tests covering all scenarios (272 total tests passing)
Usage Examples
Implementation Details
Changes Made
New Types (
src/types/index.ts
):LogFormatConfig
interface withincludeIsoTimestamp
andincludeLocalTime
optionsLoggerConfig
interface with optionalformat
propertyEnhanced MessageFormatter (
src/formatter/message-formatter.ts
):format()
method to accept optionalLogFormatConfig
parameterformatSystemMessage()
for consistencyUpdated Logger Core (
src/logger/core.ts
):Comprehensive Testing (
src/__tests__/format-customization.test.ts
):Documentation (
README.md
):Technical Approach
Use Cases
Testing
All existing tests continue to pass, ensuring no breaking changes:
Breaking Changes
None - This is a fully backward-compatible addition. Existing code continues to work without any modifications.
Related Issues
Closes #[issue-number] - Add Support for Customizing Log Elements
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
api.example.com
/usr/local/bin/node /home/REDACTED/work/log-engine/log-engine/node_modules/jest-worker/build/workers/processChild.js
(dns block)downloads.snyk.io
/usr/local/bin/node wrapper_dist/bootstrap.js exec
(dns block)o30291.ingest.sentry.io
/usr/local/bin/node wrapper_dist/bootstrap.js exec
(dns block)static.snyk.io
/usr/local/bin/node wrapper_dist/bootstrap.js exec
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.