Files
jackwener__opencli/src/logger.ts
jackwener 68840fc85c refactor: P0 architecture improvements
- Split browser.ts (700 lines) into src/browser/ module (page, mcp, errors, discover, tabs, index)
- Add unified error handling: CliError base class + logger module
- Enable TypeScript strict mode, fix 12 type errors
- Extract inline build scripts to scripts/clean-yaml.cjs and copy-yaml.cjs
- All 178 unit tests pass, build produces 83 entries across 19 sites
2026-03-17 17:01:51 +08:00

58 lines
1.5 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Unified logging for opencli.
*
* All framework output (warnings, debug info, errors) should go through
* this module so that verbosity levels are respected consistently.
*/
import chalk from 'chalk';
function isVerbose(): boolean {
return !!process.env.OPENCLI_VERBOSE;
}
function isDebug(): boolean {
return !!process.env.DEBUG?.includes('opencli');
}
export const log = {
/** Informational message (always shown) */
info(msg: string): void {
process.stderr.write(`${chalk.blue('ℹ')} ${msg}\n`);
},
/** Warning (always shown) */
warn(msg: string): void {
process.stderr.write(`${chalk.yellow('⚠')} ${msg}\n`);
},
/** Error (always shown) */
error(msg: string): void {
process.stderr.write(`${chalk.red('✖')} ${msg}\n`);
},
/** Verbose output (only when OPENCLI_VERBOSE is set or -v flag) */
verbose(msg: string): void {
if (isVerbose()) {
process.stderr.write(`${chalk.dim('[verbose]')} ${msg}\n`);
}
},
/** Debug output (only when DEBUG includes 'opencli') */
debug(msg: string): void {
if (isDebug()) {
process.stderr.write(`${chalk.dim('[debug]')} ${msg}\n`);
}
},
/** Step-style debug (for pipeline steps, etc.) */
step(stepNum: number, total: number, op: string, preview: string = ''): void {
process.stderr.write(` ${chalk.dim(`[${stepNum}/${total}]`)} ${chalk.bold.cyan(op)}${preview}\n`);
},
/** Step result summary */
stepResult(summary: string): void {
process.stderr.write(` ${chalk.dim(`→ ${summary}`)}\n`);
},
};