Skip to content

Commit

Permalink
Only log errors and above when we run unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smarr committed May 1, 2023
1 parent e671f32 commit 61bd00a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@ import { Logger } from 'tslog';
// 0: silly, 1: trace, 2: debug, 3: info, 4: warn, 5: error, 6: fatal
const trace = 2;
const info = 3;
const error = 5;

const minLevel = ('DEV' in process.env ? process.env.DEV === 'true' : false)
? trace
: info;
function getLoggingLevel(): number {
if (
('NODE_ENV' in process.env && process.env.NODE_ENV === 'test') ||
('JEST_WORKER_ID' in process.env &&
process.env.JEST_WORKER_ID !== undefined)
) {
return error;
}

if ('DEV' in process.env && process.env.DEV === 'true') {
return trace;
}

return info;
}

const minLevel = getLoggingLevel();

export const log = new Logger({ name: 'index', minLevel });

Expand Down

0 comments on commit 61bd00a

Please sign in to comment.