Repository navigation
Closed
Description
Problem
Minimal logging with console.log; hard to debug issues; no metrics for monitoring agent health.
Acceptance Criteria
- Structured JSON logging to stdout (machine-parseable)
- Error logs to stderr
- Metrics collected: execution time, items processed, blockers found
- Configurable log level (info, debug, error)
- Log includes context: PR number, repo, commit SHA, timestamp
- No sensitive data logged (no tokens, passwords)
Implementation Plan
1. Create Logger Utility (scripts/utils/logger.js)
class Logger {
constructor(level = 'info') {
this.level = level;
this.levelMap = { debug: 0, info: 1, warn: 2, error: 3 };
}
log(level, message, data = {}) {
if (this.levelMap[level] >= this.levelMap[this.level]) {
const output = {
timestamp: new Date().toISOString(),
level,
message,
...data
};
const stream = level === 'error' ? stderr : stdout;
stream.write(JSON.stringify(output) + '\\n');
}
}
debug(message, data) { this.log('debug', message, data); }
info(message, data) { this.log('info', message, data); }
warn(message, data) { this.log('warn', message, data); }
error(message, data) { this.log('error', message, data); }
}
module.exports = { Logger };2. Update Both Agents to Use Logger
const { Logger } = require('../utils/logger');
const logger = new Logger(process.env.LOG_LEVEL || 'info');
async function run(context) {
const startTime = Date.now();
logger.info('Agent started', { event: 'start' });
try {
// ...
logger.info('Agent finished', {
event: 'complete',
duration: Date.now() - startTime,
itemsProcessed: 5
});
} catch (error) {
logger.error('Agent failed', {
event: 'error',
error: error.message,
duration: Date.now() - startTime
});
}
}3. Metrics to Collect
- Execution time (start to finish)
- API calls made (count by endpoint)
- Items analyzed (files, issues, etc.)
- Blockers/issues found
- Errors encountered
Test Plan
# Test normal log level
LOG_LEVEL=info node scripts/agents/reviewer.agent.js | grep -v timestamp
# Test debug log level
LOG_LEVEL=debug node scripts/agents/reviewer.agent.js
# Parse JSON output
node scripts/agents/reviewer.agent.js | jq '.level' # Should be 'info', 'error', etc.Effort Estimate
Medium (2-3 hours)
Priority
🟢 LOW - Polish/observability
Dependencies
- Requires: Phase 1 & 2 completed
Related Issues
- Reference: ai/improvement-plan-planner-reviewer.md (Issue 3.1)
References
scripts/agents/planner.agent.js(current logging)scripts/agents/reviewer.agent.js(current logging)
Metadata
Metadata
Assignees
Type
Fields
Priority
None yet
Activity
linear-code commentedon May 31, 2026
LS-798
Phase 3: Structured Logging & Documentation (#635)
Complete Phase 3: Integrate Logger utility and create documentation r…
Complete Phase 3: Integrate Logger utility and create documentation r…
Phase 3 Polish: Complete Agent Implementation and Polish (#641)
Phase 3: Structured Logging & Documentation (#635)
Phase 3 Polish: Complete Agent Implementation and Polish (#641)
Wave 5 Issue #670 Phase 3: Standardize plugin and .github subdirector…