Skip to content

Commit

Permalink
updated logger
Browse files Browse the repository at this point in the history
  • Loading branch information
karmaniverous committed May 22, 2024
1 parent 18577f8 commit e5ed66f
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/util/logger.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import _ from 'lodash';
import { type ILogObj, Logger } from 'tslog';

import { packageName } from './packageName';

const logLevel = _.parseInt(process.env.LOG_LEVEL ?? '');
// These are the presefined tslog log levels. You can specify
// LOG_LEVEL by any of the keys or values defined below.
const logLevels: Record<string, number | undefined> = {
silly: 0,
trace: 1,
debug: 2,
info: 3,
warn: 4,
error: 5,
fatal: 6,
};

const integerLogLevel = parseInt(process.env.LOG_LEVEL ?? '');

const resolvedLogLevel = Number.isNaN(integerLogLevel)
? logLevels[(process.env.LOG_LEVEL ?? '').toLowerCase()]
: integerLogLevel;

// Set your tslog instance options here! By default, logs are suppressed if LOG_LEVEL is invalid or undefined.
// See https://tslog.js.org for more info.
export const logger = new Logger<ILogObj>({
hideLogPositionForProduction: true,
minLevel: _.isNaN(logLevel) ? undefined : logLevel,
minLevel: resolvedLogLevel,
name: packageName,
type: _.isNaN(logLevel) ? 'hidden' : 'pretty',
type: resolvedLogLevel === undefined ? 'hidden' : 'pretty',
});

0 comments on commit e5ed66f

Please sign in to comment.