Skip to content

Commit

Permalink
feat(tasks): allow log task to take silent as a level
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 4, 2021
1 parent f9d9b27 commit 19170ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
12 changes: 5 additions & 7 deletions src/tasks/stdio/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ const color = {
* of the call.
* @returns Task
*/
export function log(
level: Exclude<LogLevel, 'silent'>,
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',
Expand Down
8 changes: 2 additions & 6 deletions src/tasks/transform/catches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}

0 comments on commit 19170ca

Please sign in to comment.