askeroo
Version:
A modern CLI prompt library with flow control, history navigation, and conditional prompts
58 lines • 1.53 kB
JavaScript
/**
* Utility functions for logging and debugging
*/
/**
* Utility function for consistent result logging across examples
*/
export const logResult = (result, label = "Result") => {
console.log(`\n${label}:`, JSON.stringify(result, null, 2));
};
/**
* Simple debug logger for development
* Enable with --debug flag
*/
class DebugLogger {
isEnabled = false;
startTime = Date.now();
constructor() {
this.isEnabled = process.argv.includes("--debug");
if (this.isEnabled) {
console.log("🐛 Debug mode enabled");
}
}
log(event, data) {
if (!this.isEnabled)
return;
const elapsed = Date.now() - this.startTime;
const timestamp = `+${elapsed}ms`;
if (data !== undefined) {
console.log(`[${timestamp}] ${event}:`, data);
}
else {
console.log(`[${timestamp}] ${event}`);
}
}
isDebugEnabled() {
return this.isEnabled;
}
cleanup() {
if (this.isEnabled) {
console.log("🐛 Debug session ended");
}
}
}
// Singleton instance
let debugLoggerInstance = null;
export function getDebugLogger() {
if (!debugLoggerInstance) {
debugLoggerInstance = new DebugLogger();
}
return debugLoggerInstance;
}
// Export singleton with proxy for backward compatibility
export const debugLogger = new Proxy({}, {
get(target, prop) {
return getDebugLogger()[prop];
},
});
//# sourceMappingURL=logging.js.map