本文整理匯總了TypeScript中@coder/logger.logger.named方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript logger.named方法的具體用法?TypeScript logger.named怎麽用?TypeScript logger.named使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@coder/logger.logger
的用法示例。
在下文中一共展示了logger.named方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: field
export const run = (name: string = process.argv[2]): void | Promise<void> => {
const task = tasks.get(name);
if (!task) {
logger.error("Task not found.", field("name", name), field("available", Array.from(tasks.keys())));
return process.exit(1);
}
if (activated.has(name)) {
return activated.get(name);
}
let cwd: string = process.cwd();
const log = logger.named(name);
const timer = time(Number.MAX_SAFE_INTEGER);
let outputTimer: NodeJS.Timer | undefined;
log.info("Starting...");
const prom = task.func({
set cwd(path: string) {
cwd = path;
},
execute(command: string, args: string[] = [], env?: object): Promise<CommandResult> {
const prom = execute(command, args, {
cwd,
env: env as NodeJS.ProcessEnv,
}, log);
return prom.then((result: CommandResult) => {
if (result.exitCode != 0) {
log.error("failed",
field("exitCode", result.exitCode),
field("stdout", result.stdout),
field("stderr", result.stderr)
);
}
return result;
});
},
}, ...process.argv.slice(3));
if (prom) {
activated.set(name, prom);
const doOutput = (): void => {
outputTimer = setTimeout(() => {
log.info("Still running...");
doOutput();
}, 60 * 1000 * 5);
};
doOutput();
prom.then(() => {
if (outputTimer) {
clearTimeout(outputTimer);
}
log.info("Completed!", field("time", timer));
}).catch((ex) => {
activated.delete(name);
log.error(`Failed: ${ex.message}`);
log.error(`Stack: ${ex.stack}`);
return process.exit(1);
});
}
return prom;
};