feat(logging): replace 207 console.log/error/warn with pino structured logger (#58)

- Add pino + pino-pretty dependencies
- Create src/utils/logger.js with env-based LOG_LEVEL
- Replace all 207 console.log/error/warn calls across 46 source files
- Remove [DEBUG], [ERROR] string prefixes (levels convey this)
- Add pino redact for sensitive fields (mnemonic, privateKey, token, etc.)
- Structured logging with context objects instead of string interpolation
- NODE_ENV=production disables pino-pretty transport

49 files changed, 5601 insertions, 6056 deletions
This commit is contained in:
NW
2026-06-22 01:42:47 +01:00
parent ba80784ae7
commit ce1b6003cb
49 changed files with 5624 additions and 6079 deletions

View File

@@ -2,6 +2,7 @@ import { runMigrations, cleanUpInvalidForeignKeys } from './migrations/runner.js
import './router/routes.js';
import bot from './context/bot.js';
import ErrorHandler from './utils/errorHandler.js';
import logger from './utils/logger.js';
import userHandler from './handlers/userHandlers/userHandler.js';
import adminHandler from './handlers/adminHandlers/adminHandler.js';
import callbackRouter from './router/callbackRouter.js';
@@ -11,8 +12,7 @@ await runMigrations();
await cleanUpInvalidForeignKeys();
const logDebug = (action, functionName) => {
console.log(`[DEBUG] Button Press: ${action}`);
console.log(`[DEBUG] Calling Function: ${functionName}`);
logger.debug({ action, functionName }, 'Button Press');
};
bot.onText(/\/start/, async (msg) => {
@@ -63,7 +63,7 @@ bot.on('callback_query', async (callbackQuery) => {
bot.on('polling_error', ErrorHandler.handlePollingError);
process.on('unhandledRejection', (error) => {
console.error('Unhandled promise rejection:', error);
logger.error({ err: error }, 'Unhandled promise rejection');
});
console.log('Bot is running...');
logger.info('Bot is running...');