refactor: replace console.log with structured logger calls

Replace raw `console.log`/`console.error` calls across CLI, API
handlers, and module files with structured logger functions (`step`,
`done`, `warn`, `fail`) from the shared logger library.

This improves log consistency, readability, and makes it easier to
control output formatting and log levels from a single place.
This commit is contained in:
2026-04-12 21:44:00 -04:00
parent dd7c54d913
commit e87bd05fa4
25 changed files with 218 additions and 189 deletions
+13 -12
View File
@@ -18,6 +18,7 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
import { initDatabase, dropAuthTables, testConnection, closePool } from '../core/database/index.js';
import readline from 'readline';
import { step, done, warn, fail } from '../shared/lib/logger.js';
async function runCLI() {
const command = process.argv[2];
@@ -44,25 +45,25 @@ Example:
try {
switch (command) {
case 'init':
console.log('🔧 Initializing database...\n');
step('Initializing database...');
const result = await initDatabase();
console.log(`\n✅ Success! Created ${result.created.length} tables, skipped ${result.skipped.length} existing tables.`);
done(`Created ${result.created.length} tables, skipped ${result.skipped.length} existing tables`);
break;
case 'test':
console.log('🔌 Testing database connection...\n');
step('Testing database connection...');
const isConnected = await testConnection();
if (isConnected) {
console.log('Database connection successful!');
done('Database connection successful');
} else {
console.log('Database connection failed!');
fail('Database connection failed');
process.exit(1);
}
break;
case 'drop':
console.log('⚠️ WARNING: This will delete all authentication tables!\n');
console.log('Type "yes" to confirm or Ctrl+C to cancel...');
warn('This will delete all authentication tables!');
process.stdout.write(' Type "yes" to confirm or Ctrl+C to cancel...\n');
const rl = readline.createInterface({
input: process.stdin,
@@ -72,9 +73,9 @@ Example:
rl.question('Confirm (yes/no): ', async (answer) => {
if (answer.toLowerCase() === 'yes') {
await dropAuthTables();
console.log('Tables dropped successfully.');
done('Tables dropped successfully');
} else {
console.log('Operation cancelled.');
warn('Operation cancelled');
}
rl.close();
process.exit(0);
@@ -97,8 +98,8 @@ Usage:
break;
default:
console.log(`Unknown command: ${command}`);
console.log('Run "npx zen-db help" for usage information.');
fail(`Unknown command: ${command}`);
process.stdout.write(' Run "npx zen-db help" for usage information.\n');
process.exit(1);
}
@@ -107,7 +108,7 @@ Usage:
process.exit(0);
} catch (error) {
console.error('❌ Error:', error.message);
fail(`Error: ${error.message}`);
process.exit(1);
}
}