[grade=A] P1-8: replace 66 console.* calls across 6 remaining files with structured logger

Files changed:
- src/security/crypto-utils.js: 16 calls → log tagged 'crypto'
- src/security/docker-security.js: 15 calls → log tagged 'security'
- src/managers/port-lock-manager.js: 16 calls → log tagged 'portlock'
- src/docker/self-updater.js: 10 calls → log tagged 'updater'
- src/security/event-workers.js: 5 calls → log tagged 'events'
- src/security/keychain-manager.js: 4 calls → log tagged 'keychain'

Fixed 2 bugs found during sweep:
- self-updater.js:161 — arrow expression body had trailing semicolon (SyntaxError)
- port-lock-manager.js:137 — log.error referenced 'port' var out of scope (ReferenceError)

1539/1539 Jest tests pass. All ESLint warnings pre-existing (0 new).
This commit is contained in:
Hermes
2026-08-10 20:23:58 -07:00
parent 191d3340a7
commit 7b04bc1d3c
6 changed files with 72 additions and 71 deletions
+17 -16
View File
@@ -8,6 +8,7 @@ const fs = require('fs');
const path = require('path');
const lockfile = require('proper-lockfile');
const platformPaths = require('../../platform-paths');
const { log } = require('../utils/logging');
const LOCK_DIR = process.env.PORT_LOCK_DIR || path.join(platformPaths.dataDir, '.port-locks');
const LOCK_TIMEOUT = 120000; // 2 minutes
@@ -35,7 +36,7 @@ class PortLockManager {
ensureLockDirectory() {
if (!fs.existsSync(LOCK_DIR)) {
fs.mkdirSync(LOCK_DIR, { recursive: true });
console.log('[PortLockManager] Created lock directory:', LOCK_DIR);
log.info('portlock', 'Created lock directory', { dir: LOCK_DIR });
}
}
@@ -63,7 +64,7 @@ class PortLockManager {
const releaseFunctions = [];
try {
console.log(`[PortLockManager] Acquiring locks for ports: ${sortedPorts.join(', ')}`);
log.info('portlock', 'Acquiring locks', { ports: sortedPorts });
// Acquire locks in sorted order to prevent deadlocks
for (const port of sortedPorts) {
@@ -83,7 +84,7 @@ class PortLockManager {
acquiredLocks.push(port);
releaseFunctions.push(release);
console.log(`[PortLockManager] Locked port ${port}`);
log.info('portlock', 'Locked port', { port });
}
// Store lock information
@@ -93,18 +94,18 @@ class PortLockManager {
timestamp: Date.now()
});
console.log(`[PortLockManager] Successfully acquired all locks (ID: ${lockId})`);
log.info('portlock', 'Acquired all locks', { lockId });
return lockId;
} catch (error) {
// Release any locks we managed to acquire
console.error(`[PortLockManager] Failed to acquire all locks:`, error.message);
log.error('portlock', error, { operation: 'acquire', lockId });
for (const release of releaseFunctions) {
try {
await release();
} catch (releaseError) {
console.error(`[PortLockManager] Error releasing lock during cleanup:`, releaseError.message);
log.error('portlock', releaseError, { operation: 'releaseCleanup', lockId });
}
}
@@ -120,11 +121,11 @@ class PortLockManager {
const lockInfo = this.activeLocks.get(lockId);
if (!lockInfo) {
console.warn(`[PortLockManager] Lock ID ${lockId} not found (may have been released already)`);
log.warn('portlock', 'Lock ID not found', { lockId });
return;
}
console.log(`[PortLockManager] Releasing locks for ports: ${lockInfo.ports.join(', ')}`);
log.info('portlock', 'Releasing locks', { lockId, ports: lockInfo.ports });
const errors = [];
@@ -133,16 +134,16 @@ class PortLockManager {
await release();
} catch (error) {
errors.push(error.message);
console.error(`[PortLockManager] Error releasing lock:`, error.message);
log.error('portlock', error, { operation: 'release', lockId });
}
}
this.activeLocks.delete(lockId);
if (errors.length > 0) {
console.warn(`[PortLockManager] Released locks with ${errors.length} errors`);
log.warn('portlock', 'Released locks with errors', { lockId, errorCount: errors.length });
} else {
console.log(`[PortLockManager] Successfully released all locks (ID: ${lockId})`);
log.info('portlock', 'Released all locks', { lockId });
}
}
@@ -151,7 +152,7 @@ class PortLockManager {
* Removes locks older than LOCK_STALE_THRESHOLD
*/
async cleanupStaleLocks() {
console.log('[PortLockManager] Cleaning up stale locks...');
log.info('portlock', 'Cleaning up stale locks');
this.ensureLockDirectory();
@@ -174,20 +175,20 @@ class PortLockManager {
// Lock is stale or not locked, safe to remove
fs.unlinkSync(lockFilePath);
cleaned++;
console.log(`[PortLockManager] Removed stale lock: ${file}`);
log.info('portlock', 'Removed stale lock', { file });
}
} catch (error) {
// File might not exist or might have been removed by another process
if (error.code !== 'ENOENT') {
errors++;
console.warn(`[PortLockManager] Error checking lock ${file}:`, error.message);
log.warn('portlock', 'Error checking lock', { file, error: error.message });
}
}
}
console.log(`[PortLockManager] Cleanup complete: ${cleaned} stale locks removed, ${errors} errors`);
log.info('portlock', 'Cleanup complete', { cleaned, errors });
} catch (error) {
console.error('[PortLockManager] Error during cleanup:', error.message);
log.error('portlock', error, { operation: 'cleanup' });
}
}