zephyr-agent
Version:
Zephyr plugin agent
79 lines (78 loc) • 3.46 kB
JavaScript
import "node:module";
import debug from "debug";
import { bgCyanBright, bgGreenBright, bgRedBright, bgYellowBright, black, bold, dim } from "./picocolor.mjs";
import { isFileLoggingEnabled, writeLogToFile } from "./file-logger.mjs";
import { redactString, safeStringifyForLogging, sanitizeForLogging } from "../security/redaction.mjs";
const debug_name = ' ZEPHYR ';
const dimmedName = dim(debug_name);
const brightBlueBgName = bold(bgCyanBright(black(debug_name)));
const brightYellowBgName = bold(bgYellowBright(black(debug_name)));
const brightGreenBgName = bold(bgGreenBright(black(debug_name)));
const brightRedBgName = bold(bgRedBright(black(debug_name)));
function wrapDebugLogger(logger, context) {
const wrappedFn = (...args)=>{
const fileLoggingEnabled = isFileLoggingEnabled();
if (!fileLoggingEnabled && !logger.enabled) return;
const sanitizedArgs = args.map((arg)=>sanitizeForLogging(arg));
if (fileLoggingEnabled) {
const message = sanitizedArgs.map(formatDebugArgument).join(' ');
writeLogToFile({
level: 'debug',
message,
action: `debug:${context}`,
timestamp: Date.now()
});
}
if (!logger.enabled) return;
logger(...sanitizedArgs);
};
return Object.assign(wrappedFn, {
enabled: logger.enabled,
namespace: logger.namespace
});
}
function formatDebugArgument(arg) {
if ('string' == typeof arg) return redactString(arg);
return safeStringifyForLogging(arg);
}
const rawLoggers = {
app: debug('zephyr:app'),
auth: debug('zephyr:auth'),
buildstats: debug('zephyr:buildstats'),
config: debug('zephyr:config'),
git: debug('zephyr:git'),
http: debug('zephyr:http'),
init: debug('zephyr:init'),
manifest: debug('zephyr:manifest'),
mf: debug('zephyr:mf'),
misc: debug('zephyr:misc'),
package: debug('zephyr:package'),
remotes: debug('zephyr:remotes'),
snapshot: debug('zephyr:snapshot'),
upload: debug('zephyr:upload'),
debug: debug('zephyr:debug'),
error: debug('zephyr:error')
};
const ze_error = wrapDebugLogger(rawLoggers.error, 'error');
const ze_debug = wrapDebugLogger(rawLoggers.debug, 'debug');
const createLogger = ()=>({
app: wrapDebugLogger(rawLoggers.app, 'app'),
auth: wrapDebugLogger(rawLoggers.auth, 'auth'),
buildstats: wrapDebugLogger(rawLoggers.buildstats, 'buildstats'),
config: wrapDebugLogger(rawLoggers.config, 'config'),
git: wrapDebugLogger(rawLoggers.git, 'git'),
http: wrapDebugLogger(rawLoggers.http, 'http'),
init: wrapDebugLogger(rawLoggers.init, 'init'),
manifest: wrapDebugLogger(rawLoggers.manifest, 'manifest'),
mf: wrapDebugLogger(rawLoggers.mf, 'mf'),
misc: wrapDebugLogger(rawLoggers.misc, 'misc'),
package: wrapDebugLogger(rawLoggers.package, 'package'),
remotes: wrapDebugLogger(rawLoggers.remotes, 'remotes'),
snapshot: wrapDebugLogger(rawLoggers.snapshot, 'snapshot'),
upload: wrapDebugLogger(rawLoggers.upload, 'upload'),
debug: wrapDebugLogger(rawLoggers.debug, 'debug'),
error: wrapDebugLogger(rawLoggers.error, 'error')
});
const ze_log = createLogger();
export { brightBlueBgName, brightGreenBgName, brightRedBgName, brightYellowBgName, dimmedName, ze_debug, ze_error, ze_log };
//# sourceMappingURL=debug.mjs.map