Skip to content

Add Support for Customizing Log Elements While Keeping Log Levels Mandatory #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 1, 2025

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

import { LogEngine, LogMode } from '@wgtechlabs/log-engine';

// Default format (backward compatible)
LogEngine.configure({ mode: LogMode.DEBUG });
LogEngine.info('Server started');
// Output: [2025-05-29T16:57:45.678Z][4:57PM][INFO]: Server started

// Only ISO timestamp
LogEngine.configure({ 
  mode: LogMode.DEBUG,
  format: {
    includeIsoTimestamp: true,
    includeLocalTime: false
  }
});
LogEngine.info('Database connected');
// Output: [2025-05-29T16:57:45.678Z][INFO]: Database connected

// Minimal format (no timestamps)
LogEngine.configure({ 
  mode: LogMode.DEBUG,
  format: {
    includeIsoTimestamp: false,
    includeLocalTime: false
  }
});
LogEngine.error('Connection failed');
// Output: [ERROR]: Connection failed

Implementation Details

Changes Made

  1. New Types (src/types/index.ts):

    • Added LogFormatConfig interface with includeIsoTimestamp and includeLocalTime options
    • Extended LoggerConfig interface with optional format property
  2. Enhanced MessageFormatter (src/formatter/message-formatter.ts):

    • Updated format() method to accept optional LogFormatConfig parameter
    • Implemented conditional timestamp formatting logic
    • Updated formatSystemMessage() for consistency
    • Maintained backward compatibility when no format config is provided
  3. Updated Logger Core (src/logger/core.ts):

    • Modified all logging methods to pass format configuration to MessageFormatter
    • Ensured configuration flows through both standard and raw logging methods
  4. Comprehensive Testing (src/__tests__/format-customization.test.ts):

    • 17 new tests covering all format combinations
    • Backward compatibility validation
    • Edge cases and error handling
    • LogEngine integration testing
  5. Documentation (README.md):

    • Added complete section on log element customization
    • Usage examples for all format combinations
    • Benefits and use cases explained

Technical Approach

  • Minimal Changes: Surgical implementation touching only essential files
  • Default Behavior: Uses spread operator to maintain defaults when no config provided
  • Performance: Conditional timestamp generation only when needed
  • Type Safety: Full TypeScript support with proper interfaces

Use Cases

  • 🎯 Reduced Verbosity: Remove timestamps in containerized environments where external logging systems add timestamps
  • 📱 Space Efficiency: Minimize log line length for mobile or constrained display environments
  • 🔧 Integration Ready: Match existing log format requirements in infrastructure
  • ⚡ Performance: Slightly reduced formatting overhead when timestamps are disabled

Testing

All existing tests continue to pass, ensuring no breaking changes:

  • 272 total tests passing (255 existing + 17 new)
  • 100% backward compatibility verified
  • All linting rules passed
  • Manual validation confirms expected behavior

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
    • Triggering command: /usr/local/bin/node /home/REDACTED/work/log-engine/log-engine/node_modules/jest-worker/build/workers/processChild.js (dns block)
  • downloads.snyk.io
    • Triggering command: /usr/local/bin/node wrapper_dist/bootstrap.js exec (dns block)
  • o30291.ingest.sentry.io
    • Triggering command: /usr/local/bin/node wrapper_dist/bootstrap.js exec (dns block)
  • static.snyk.io
    • Triggering command: /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.

@Copilot Copilot AI changed the title [WIP] Add support for customizing log elements except log levels Add Support for Customizing Log Elements While Keeping Log Levels Mandatory Jul 1, 2025
@Copilot Copilot AI requested a review from warengonzaga July 1, 2025 06:12
Copilot finished work on behalf of warengonzaga July 1, 2025 06:12
@warengonzaga warengonzaga changed the base branch from main to dev July 1, 2025 06:14
@warengonzaga
Copy link
Member

This is a live example of using Coding Agent from GitHub mobile. 🤝
Posted it here: https://x.com/warengonzaga/status/1939929236183167311

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants