Improve logging, rate limiting, and error handling (#29)

* feat: apply local user changes and fixes

* ;D

* Clean up PR #28: Remove duplicate code lines and unnecessary file

- Remove pullrequest.md (PR notes file not needed in repo)
- Fix duplicate lines in account-manager.js:
  - rateLimitResetTime assignment
  - saveToDisk() calls in markRateLimited and markInvalid
  - invalidReason/invalidAt assignments
  - double return statement in discoverProject

Original PR by M2noa: fix sticky accs, 500s, logging updates, and rate limit handling

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: M2noa <226494568+M2noa@users.noreply.github.com>
Co-Authored-By: Claude <noreply@anthropic.com>

* chore: replace console.log with logger methods for consistency

- Replace all console.log calls with logger.warn/debug in:
  - src/cloudcode-client.js (4 places)
  - src/format/thinking-utils.js (7 places)

This ensures consistent logging behavior with the new logger utility,
respecting --debug mode for verbose output.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: M1noa <minoa@minoa.cat>
Co-authored-by: M2noa <226494568+M2noa@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Badri Narayanan S
2026-01-01 14:35:06 +05:30
committed by GitHub
parent d05fb64e29
commit 1d91bc0d30
11 changed files with 351 additions and 108 deletions

114
src/utils/logger.js Normal file
View File

@@ -0,0 +1,114 @@
/**
* Logger Utility
*
* Provides structured logging with colors and debug support.
* Simple ANSI codes used to avoid dependencies.
*/
const COLORS = {
RESET: '\x1b[0m',
BRIGHT: '\x1b[1m',
DIM: '\x1b[2m',
RED: '\x1b[31m',
GREEN: '\x1b[32m',
YELLOW: '\x1b[33m',
BLUE: '\x1b[34m',
MAGENTA: '\x1b[35m',
CYAN: '\x1b[36m',
WHITE: '\x1b[37m',
GRAY: '\x1b[90m'
};
class Logger {
constructor() {
this.isDebugEnabled = false;
}
/**
* Set debug mode
* @param {boolean} enabled
*/
setDebug(enabled) {
this.isDebugEnabled = !!enabled;
}
/**
* Get current timestamp string
*/
getTimestamp() {
return new Date().toISOString();
}
/**
* Format and print a log message
* @param {string} level
* @param {string} color
* @param {string} message
* @param {...any} args
*/
print(level, color, message, ...args) {
// Format: [TIMESTAMP] [LEVEL] Message
const timestamp = `${COLORS.GRAY}[${this.getTimestamp()}]${COLORS.RESET}`;
const levelTag = `${color}[${level}]${COLORS.RESET}`;
console.log(`${timestamp} ${levelTag} ${message}`, ...args);
}
/**
* Standard info log
*/
info(message, ...args) {
this.print('INFO', COLORS.BLUE, message, ...args);
}
/**
* Success log
*/
success(message, ...args) {
this.print('SUCCESS', COLORS.GREEN, message, ...args);
}
/**
* Warning log
*/
warn(message, ...args) {
this.print('WARN', COLORS.YELLOW, message, ...args);
}
/**
* Error log
*/
error(message, ...args) {
this.print('ERROR', COLORS.RED, message, ...args);
}
/**
* Debug log - only prints if debug mode is enabled
*/
debug(message, ...args) {
if (this.isDebugEnabled) {
this.print('DEBUG', COLORS.MAGENTA, message, ...args);
}
}
/**
* Direct log (for raw output usually) - proxied to console.log but can be enhanced
*/
log(message, ...args) {
console.log(message, ...args);
}
/**
* Print a section header
*/
header(title) {
console.log(`\n${COLORS.BRIGHT}${COLORS.CYAN}=== ${title} ===${COLORS.RESET}\n`);
}
}
// Export a singleton instance
export const logger = new Logger();
// Export class if needed for multiple instances
export { Logger };