Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 21, 2025

This PR migrates the console logging system from a custom implementation to @wgtechlabs/log-engine v2.2.0, implementing a clean, emoji-free logging format that shows only error type and local time as requested.

Changes Made

🔧 Complete Logger Migration

  • Replaced custom logger: Migrated both src/utils/logger.js and src/utils/logger.ts from custom console logging to @wgtechlabs/log-engine
  • Added dependency: @wgtechlabs/[email protected] to package.json
  • Custom output handler: Implemented clean formatting that removes ISO timestamps and shows only local time
  • Removed legacy code: Completely eliminated ~50 lines of legacy console logging code from TypeScript logger

🧹 Clean Output Format

The new logging format follows the requirements exactly:

Before:

[2025-08-21T14:27:25.643Z][2:27PM][INFO]: Bot started successfully

After:

[14:27:25][INFO]: Bot started successfully

🚫 Emoji Removal

Removed all emojis from logging calls across the codebase:

  • src/events/ready.js & src/events/ready.ts: Removed ⚠️ and ✅ from channel validation logs
  • src/events/threadCreate.js: Removed ❌, ⚠️, ✅, 📧, 💡, 🔧, 🔐, ⏱️ from error and status logs

Total: 18 emoji instances removed across 4 files

🔄 Unified Implementation

  • Zero breaking changes: All existing logger methods (debug, info, warn, error) work unchanged
  • Environment support: DEBUG_MODE environment variable continues to control debug log visibility
  • API preservation: Existing imports and usage patterns require no modifications
  • Consistent behavior: Both JavaScript and TypeScript loggers produce identical output format

🧪 Technical Implementation

  • Custom output handler: Strips ANSI color codes and extracts clean message content
  • Message parsing: Removes log-engine's default formatting to show only level and local time
  • Error handling: Maintains proper console routing for error/warn streams
  • TypeScript compatibility: Project builds successfully with all changes

Testing

  • ✅ Manual testing with various log levels and scenarios
  • ✅ DEBUG_MODE environment variable functionality verified
  • ✅ TypeScript compilation successful
  • ✅ Integration testing with realistic bot logging scenarios
  • ✅ Both JavaScript and TypeScript loggers tested and working identically

This migration follows KISS (Keep It Simple, Stupid) and Clean Code principles, providing a modern, secure logging solution while maintaining the exact output format requirements and completely eliminating all legacy console logging code.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Can we migrate our console logging system by using a library such as this: @wgtechlabs/log-engine using their latest version. Also, check the read me file of this project and ensure you are removing the ISO timestamp log element and only allow the type... Migrate console logging to @wgtechlabs/log-engine and remove emojis from logs Aug 21, 2025
@Copilot Copilot AI requested a review from warengonzaga August 21, 2025 14:29
Copilot finished work on behalf of warengonzaga August 21, 2025 14:29
@warengonzaga warengonzaga marked this pull request as ready for review August 21, 2025 14:30
@Copilot Copilot AI review requested due to automatic review settings August 21, 2025 14:30
@warengonzaga warengonzaga added the api API integration and external services (Issues/PRs) label Aug 21, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the logging system from a custom implementation to @wgtechlabs/log-engine v2.2.0 while removing emojis from all log messages to achieve a cleaner output format showing only error type and local time.

  • Replaced custom logger implementation with @wgtechlabs/log-engine integration
  • Removed 18 emoji instances from log messages across event handlers
  • Implemented custom output handler to format logs as [HH:MM:SS][LEVEL]: message

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/utils/logger.js Complete migration to @wgtechlabs/log-engine with custom output formatting
src/events/threadCreate.js Removed emojis (❌, ⚠️, ✅, 📧, 💡, 🔧, 🔐, ⏱️) from error and status logs
src/events/ready.ts Removed emojis (⚠️, ✅) from channel validation logs
src/events/ready.js Removed emojis (⚠️, ✅) from channel validation logs
package.json Added @wgtechlabs/[email protected] dependency

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

const messageMatch = cleanMessage.match(/^.*?\[.*?\].*?\[.*?\].*?\[.*?\]:\s*(.*)$/);
if (messageMatch && messageMatch[1]) {
cleanMessage = messageMatch[1].trim();

Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern for extracting message content is fragile and may break if the log-engine's internal format changes. Consider using a more robust parsing approach or documenting the dependency on this specific format.

Suggested change
// This approach splits at the first occurrence of ']:', which should follow the last prefix.
// If the log-engine's format changes, update this logic accordingly.
const splitIndex = cleanMessage.indexOf(']:');
if (splitIndex !== -1) {
cleanMessage = cleanMessage.slice(splitIndex + 2).trim();

Copilot uses AI. Check for mistakes.

cleanMessage = messageMatch[1].trim();

// Remove any JSON data that might be appended to the message
cleanMessage = cleanMessage.replace(/\s*\{.*\}$/, '');
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex removes all JSON-like content at the end of messages, which could accidentally remove legitimate log data. Consider a more precise approach to handle data parameters or document this limitation.

Suggested change
cleanMessage = cleanMessage.replace(/\s*\{.*\}$/, '');
// (Removed imprecise regex that stripped JSON-like content from the end of the message)
// cleanMessage = cleanMessage.replace(/\s*\{.*\}$/, '');

Copilot uses AI. Check for mistakes.

@warengonzaga
Copy link
Member

@copilot I can still see some legacy code for the console log, can we completely remove them and use the @wgtechlabs/log-engine purely here? Use the logger.ts as the configuration file instead no more legacy code for logging in console.

Copy link
Contributor Author

Copilot AI commented Aug 22, 2025

@copilot I can still see some legacy code for the console log, can we completely remove them and use the @wgtechlabs/log-engine purely here? Use the logger.ts as the configuration file instead no more...

Done! I've completely removed all legacy console logging code from logger.ts and migrated it to use @wgtechlabs/log-engine purely. The TypeScript logger now uses the same clean implementation as the JavaScript version:

  • Removed ~50 lines of legacy console.log/warn/error code
  • Migrated to LogEngine.debug(), LogEngine.info(), LogEngine.warn(), LogEngine.error()
  • Both logger.js and logger.ts now have identical @wgtechlabs/log-engine integration
  • Clean output format: [HH:MM:SS][LEVEL]: message with no emojis
  • DEBUG_MODE environment variable works correctly

Commit: 3bd08b1

Copilot finished work on behalf of warengonzaga August 22, 2025 13:45
@warengonzaga warengonzaga merged commit 52d3954 into dev Aug 23, 2025
1 check passed
@warengonzaga warengonzaga deleted the copilot/fix-f79849e6-ba43-45b7-a998-23d8cbacdd83 branch August 23, 2025 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api API integration and external services (Issues/PRs)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants