chore: added logging
This commit is contained in:
@@ -21,6 +21,7 @@ export function showHelp() {
|
||||
|
||||
console.log(chalk.yellow.bold('OPTIONS:'));
|
||||
console.log(' --config <file> YAML configuration file for authentication and testing parameters');
|
||||
console.log(' --log [file] Capture all output to log file (default: shannon-<timestamp>.log)');
|
||||
console.log(' --pipeline-testing Use minimal prompts for fast pipeline testing (creates minimal deliverables)\n');
|
||||
|
||||
console.log(chalk.yellow.bold('DEVELOPER COMMANDS:'));
|
||||
@@ -36,6 +37,7 @@ export function showHelp() {
|
||||
console.log(' # Normal mode - create new session');
|
||||
console.log(' ./shannon.mjs "https://example.com" "/path/to/local/repo"');
|
||||
console.log(' ./shannon.mjs "https://example.com" "/path/to/local/repo" --config auth.yaml');
|
||||
console.log(' ./shannon.mjs "https://example.com" "/path/to/local/repo" --log pentest.log');
|
||||
console.log(' ./shannon.mjs "https://example.com" "/path/to/local/repo" --setup-only # Setup only\n');
|
||||
|
||||
console.log(' # Developer mode - operate on existing session');
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { fs } from 'zx';
|
||||
import { path } from 'zx';
|
||||
|
||||
/**
|
||||
* Sets up logging to capture all stdout and stderr to a file
|
||||
* @param {string} logFilePath - Path to the log file
|
||||
* @returns {Promise<Function>} Cleanup function to restore original streams
|
||||
*/
|
||||
export async function setupLogging(logFilePath) {
|
||||
// Resolve to absolute path
|
||||
const absoluteLogPath = path.isAbsolute(logFilePath)
|
||||
? logFilePath
|
||||
: path.join(process.cwd(), logFilePath);
|
||||
|
||||
// Ensure the directory exists
|
||||
await fs.ensureDir(path.dirname(absoluteLogPath));
|
||||
|
||||
// Create write stream for the log file
|
||||
const logStream = fs.createWriteStream(absoluteLogPath, { flags: 'a' });
|
||||
|
||||
// Store original stdout/stderr write functions
|
||||
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
||||
const originalStderrWrite = process.stderr.write.bind(process.stderr);
|
||||
|
||||
// Override stdout
|
||||
process.stdout.write = function(chunk, encoding, callback) {
|
||||
// Write to both original stdout and log file
|
||||
originalStdoutWrite(chunk, encoding, callback);
|
||||
logStream.write(chunk, encoding);
|
||||
return true;
|
||||
};
|
||||
|
||||
// Override stderr
|
||||
process.stderr.write = function(chunk, encoding, callback) {
|
||||
// Write to both original stderr and log file
|
||||
originalStderrWrite(chunk, encoding, callback);
|
||||
logStream.write(chunk, encoding);
|
||||
return true;
|
||||
};
|
||||
|
||||
// Return cleanup function
|
||||
return async function cleanup() {
|
||||
// Restore original streams
|
||||
process.stdout.write = originalStdoutWrite;
|
||||
process.stderr.write = originalStderrWrite;
|
||||
|
||||
// Close the log stream
|
||||
return new Promise((resolve, reject) => {
|
||||
logStream.end((err) => {
|
||||
if (err) reject(err);
|
||||
else resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user