feat(logging-p0): replace console.* with logger and add error logging before ERP throws
Eliminate console.* remnants in bootstrap, session-manager, migrations, and app entry so startup and login failures are captured in log files. Add log.error before all 14 throw sites in ERP services (auth, extractor, cleaner, browser manager) to ensure critical automation failures are traceable. Introduce capturePageContext utility for defensive Playwright page state capture during error logging. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,9 @@ import { dirname } from 'path'
|
||||
import { ConfigManager } from '../../config/config-manager'
|
||||
import { MySqlService } from '../../database/mysql'
|
||||
import { SqlServerService } from '../../database/sql-server'
|
||||
import { createLogger } from '../../logger'
|
||||
|
||||
const log = createLogger('Migration')
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = dirname(__filename)
|
||||
@@ -136,7 +139,9 @@ async function runMySQLMigration(configManager: ConfigManager): Promise<void> {
|
||||
|
||||
await mysqlService.disconnect()
|
||||
} catch (error) {
|
||||
console.error('✗ MySQL Migration failed:', error instanceof Error ? error.message : error)
|
||||
log.error('MySQL Migration failed', {
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
})
|
||||
if (mysqlService.isConnected()) {
|
||||
await mysqlService.disconnect()
|
||||
}
|
||||
@@ -192,7 +197,9 @@ async function runSqlServerMigration(configManager: ConfigManager): Promise<void
|
||||
|
||||
await sqlServerService.disconnect()
|
||||
} catch (error) {
|
||||
console.error('✗ SQL Server Migration failed:', error instanceof Error ? error.message : error)
|
||||
log.error('SQL Server Migration failed', {
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
})
|
||||
if (sqlServerService.isConnected()) {
|
||||
await sqlServerService.disconnect()
|
||||
}
|
||||
@@ -223,7 +230,7 @@ async function main(): Promise<void> {
|
||||
|
||||
console.log('\n✅ Migration completed successfully!\n')
|
||||
} catch (error) {
|
||||
console.error('\n❌ Migration failed:', error instanceof Error ? error.message : error)
|
||||
log.error('Migration failed', { error: error instanceof Error ? error.message : String(error) })
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import yaml from 'js-yaml'
|
||||
import { z } from 'zod'
|
||||
import { createLogger } from '../../logger'
|
||||
|
||||
const log = createLogger('MigrationRunner')
|
||||
|
||||
/**
|
||||
* MySQL configuration schema
|
||||
@@ -105,8 +108,10 @@ async function runMigration(): Promise<void> {
|
||||
try {
|
||||
dbConfig = loadConfig(configPath)
|
||||
} catch (error) {
|
||||
console.error('Failed to load config.yaml:', error instanceof Error ? error.message : error)
|
||||
console.error('Please ensure config.yaml exists and contains valid MySQL configuration.')
|
||||
log.error('Failed to load config', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
configPath
|
||||
})
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
@@ -171,8 +176,7 @@ async function runMigration(): Promise<void> {
|
||||
console.log(` ERP_Password = 'your_password'`)
|
||||
console.log(` WHERE ERP_URL IS NULL;\n`)
|
||||
} catch (error) {
|
||||
console.error('\n❌ Migration failed with error:')
|
||||
console.error(error)
|
||||
log.error('Migration failed', { error })
|
||||
console.error('\nTroubleshooting:')
|
||||
console.error('1. Check if MySQL server is running')
|
||||
console.error('2. Verify database credentials in config.yaml file')
|
||||
@@ -194,6 +198,6 @@ async function runMigration(): Promise<void> {
|
||||
|
||||
// Run migration
|
||||
runMigration().catch((error) => {
|
||||
console.error('Unexpected error:', error)
|
||||
log.error('Unexpected error', { error })
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
*/
|
||||
|
||||
import type { UserInfo } from '../../types/user.types'
|
||||
import { createLogger } from '../logger'
|
||||
|
||||
const log = createLogger('SessionManager')
|
||||
|
||||
/**
|
||||
* Session Manager Class
|
||||
@@ -59,12 +62,12 @@ export class SessionManager {
|
||||
}
|
||||
return false
|
||||
} catch (error) {
|
||||
console.error('[SessionManager] Login error:', error)
|
||||
log.error('Login error', { error })
|
||||
return false
|
||||
} finally {
|
||||
if (dao) {
|
||||
await dao.disconnect().catch((error) => {
|
||||
console.error('[SessionManager] Login disconnect error:', error)
|
||||
log.error('Login disconnect error', { error })
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -93,12 +96,12 @@ export class SessionManager {
|
||||
}
|
||||
return false
|
||||
} catch (error) {
|
||||
console.error('[SessionManager] Silent login error:', error)
|
||||
log.error('Silent login error', { error })
|
||||
return false
|
||||
} finally {
|
||||
if (dao) {
|
||||
await dao.disconnect().catch((error) => {
|
||||
console.error('[SessionManager] Silent login disconnect error:', error)
|
||||
log.error('Silent login disconnect error', { error })
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -187,12 +190,12 @@ export class SessionManager {
|
||||
dao = new BIPUsersDAO()
|
||||
return await dao.getAllUsers()
|
||||
} catch (error) {
|
||||
console.error('[SessionManager] Get all users error:', error)
|
||||
log.error('Get all users error', { error })
|
||||
return []
|
||||
} finally {
|
||||
if (dao) {
|
||||
await dao.disconnect().catch((error) => {
|
||||
console.error('[SessionManager] Get all users disconnect error:', error)
|
||||
log.error('Get all users disconnect error', { error })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user