@sumor/logger
Advanced tools
Comparing version 1.2.5 to 1.2.6
{ | ||
"name": "@sumor/logger", | ||
"description": "This is a lightweight logger for Node.JS. It can output logs in different levels, and you can customize the scope, id, and timezone.", | ||
"version": "1.2.5", | ||
"version": "1.2.6", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": "sumor-cloud/logger", |
@@ -196,1 +196,36 @@ # logger | ||
``` | ||
### Filter Level | ||
When you want to filter logs by level, you can use the following code: | ||
```js | ||
import Logger from '@sumor/logger' | ||
const logger = new Logger({ | ||
level: 'info' | ||
}) | ||
logger.trace('Hello World!') // trace is the lowest level, will not be output | ||
logger.debug('Hello World!') // debug is lower than info, will not be output | ||
logger.info('Hello World!') // info is the same as info, will be output | ||
logger.warn('Hello World!') // warn is higher than info, will be output | ||
logger.error('Hello World!') // error is higher than info, will be output | ||
logger.fatal('Hello World!') // fatal is the highest level, will be output | ||
``` | ||
When you use this library cross multiple libraries, you can use the following code: | ||
```js | ||
import Logger from '@sumor/logger' | ||
const logger = new Logger() | ||
process.env.LOG_LEVEL = 'info' | ||
logger.trace('Hello World!') // trace is the lowest level, will not be output | ||
logger.debug('Hello World!') // debug is lower than info, will not be output | ||
logger.info('Hello World!') // info is the same as info, will be output | ||
logger.warn('Hello World!') // warn is higher than info, will be output | ||
logger.error('Hello World!') // error is higher than info, will be output | ||
process.env.LOG_LEVEL = 'warn' // real-time change log level | ||
logger.info('Hello World!') // info is lower than warn, will not be output | ||
``` |
14586
230