From 19170ca69d007fbb010641a1f8be84489abfe44d Mon Sep 17 00:00:00 2001 From: Rafa Mel Date: Sun, 4 Apr 2021 13:40:11 +0200 Subject: [PATCH] feat(tasks): allow log task to take silent as a level --- src/tasks/stdio/log.ts | 12 +++++------- src/tasks/transform/catches.ts | 8 ++------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/tasks/stdio/log.ts b/src/tasks/stdio/log.ts index 1866d24..6c93f21 100644 --- a/src/tasks/stdio/log.ts +++ b/src/tasks/stdio/log.ts @@ -33,16 +33,14 @@ const color = { * of the call. * @returns Task */ -export function log( - level: Exclude, - item: any, - ...data: any[] -): Task.Sync { - const nLevel = rank[String(level).toLowerCase()] || 5; +export function log(level: LogLevel, item: any, ...data: any[]): Task.Sync { + level = String(level) as LogLevel; + const nLevel = rank[level.toLowerCase()] || 5; return (ctx: Context): void => { - const nCurrent = rank[String(ctx.level).toLowerCase()] || 0; + if (level === 'silent' || level.toLowerCase() === 'silent') return; + const nCurrent = rank[String(ctx.level).toLowerCase()] || 0; if (nCurrent >= nLevel) { const str = addPrefix( util.format(item, ...data) + '\n', diff --git a/src/tasks/transform/catches.ts b/src/tasks/transform/catches.ts index ccbbc7c..f84b868 100644 --- a/src/tasks/transform/catches.ts +++ b/src/tasks/transform/catches.ts @@ -29,12 +29,8 @@ export function catches( try { await task(ctx); } catch (err) { - if (opts.level !== 'silent') { - into(ctx, log(opts.level, formatMessage(err))); - } - if (alternate) { - await alternate(ctx); - } + into(ctx, log(opts.level, formatMessage(err))); + if (alternate) await alternate(ctx); } }; }