Skip to content

Add colored logging with charmbracelet/log - Fixes #144#189

Closed
Eshaan-byte wants to merge 9 commits into
CCExtractor:mainfrom
Eshaan-byte:last-sync-timestamp-feature
Closed

Add colored logging with charmbracelet/log - Fixes #144#189
Eshaan-byte wants to merge 9 commits into
CCExtractor:mainfrom
Eshaan-byte:last-sync-timestamp-feature

Conversation

@Eshaan-byte
Copy link
Copy Markdown
Contributor

Description

Implements colored, structured logging using charmbracelet/log to improve backend debugging, monitoring, and developer experience.

Changes

  • ✅ Integrated charmbracelet/log for colored, structured logging
  • ✅ Created new logger utility package at backend/utils/logger/
  • ✅ Replaced all log.Println/Printf statements with structured logger calls
  • ✅ Added configurable log levels via LOG_LEVEL environment variable
  • ✅ Added timestamps to all log entries
  • ✅ Updated go.mod dependencies

Features

Color-Coded Log Levels:

  • 🟢 INFO (Green) - General informational messages
  • 🟡 WARN (Yellow) - Warning messages
  • 🔴 ERROR (Red) - Error events
  • ⚪ DEBUG (Gray) - Diagnostic information
  • 🔴 FATAL (Red, bold) - Critical errors

- Add getTimeSinceLastSync utility function to format relative time
- Store last sync timestamp in localStorage per user
- Display "Last updated X ago" below Sync button
- Auto-refresh display every 10 seconds
- Add comprehensive tests for time formatting

Fixes CCExtractor#124
- Add hashKey() function to create hash of key+email
- Update localStorage to use hashed keys instead of plain email
- Prevents storing email addresses directly in localStorage
- Add comprehensive tests for hashKey function (5 new tests)
- All 29 tests passing

Addresses review feedback from @its-me-abhishek
Implements CCExtractor#144 - Colored Logging & Improved Backend Logs

Features:
- Integrated charmbracelet/log for structured, colored logging
- Color-coded log levels (Info=Green, Warn=Yellow, Error=Red, Debug=Gray)
- Configurable log levels via LOG_LEVEL environment variable
- Structured logging with key-value pairs for better traceability
- Timestamps on all log entries
- Auto-initialization in tests for seamless testing

Changes:
- Added new logger utility package (backend/utils/logger/)
- Updated all log statements across main.go, controllers, and utils
- Replaced plain log.Println/Printf with structured logger calls
- Added LOG_LEVEL to .env configuration
- Updated go.mod with charmbracelet/log dependency

Log Levels:
- debug: Detailed diagnostic information
- info: General informational messages (default)
- warn: Warning messages for potential issues
- error: Error events that need attention
- fatal: Critical errors causing shutdown

Usage examples:
- Simple: logger.Info("Server started")
- Structured: logger.Info("User authenticated", "email", user.Email, "uuid", uuid)
- Formatted: logger.Errorf("Failed to connect: %v", err)

Benefits:
- Easier debugging with visual color coding
- Better production monitoring with structured fields
- Improved developer experience with clean, readable output
- Quick issue identification with timestamps and context
Comment thread backend/utils/logger/logger.go Outdated
@@ -0,0 +1,129 @@
package logger
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why'd we want another dependency? i think we could've used github.com/charmbracelet/log directly

- Removed utils/logger wrapper package as suggested in review
- Added global Logger variable in main package with InitLogger()
- Created logger.go in controllers and utils/tw packages for local Logger instances
- Logger instances auto-initialize in init() for test compatibility
- Maintained all existing log functionality with structured logging
- All tests pass successfully
@Eshaan-byte
Copy link
Copy Markdown
Contributor Author

@its-me-abhishek , Done I used charmbracelet now. Plese check whenever you are free.Thank you.

Copy link
Copy Markdown
Collaborator

@its-me-abhishek its-me-abhishek left a comment

Choose a reason for hiding this comment

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

The PR seems to be a breaking change, and does not really follow the project structure. Closing this for now

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.

Colored Logging & Improved Backend Logs

2 participants