generated from karmaniverous/npm-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18577f8
commit e5ed66f
Showing
1 changed file
with
21 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); |