-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsola.ts
28 lines (26 loc) · 1.06 KB
/
consola.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { createConsola } from 'consola';
/**
* A consola logger instance.
*
* The logger's level is determined based on the `CONSOLA_LOGGER_LEVEL` and `NODE_ENV` environment variables. If `CONSOLA_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`, the level will be set to `0`.
*
* To manually change the level, assign the desired level to `logger.level`.
*
* See available levels [here](https://github.com/unjs/consola?tab=readme-ov-file#log-level).
*
* @example
* ```typescript
* import logger from '@kikiutils/node/consola'; // ESM
* const { logger } = require('@kikiutils/node/consola'); // CJS
*
* logger.info('test'); // Output: 'ℹ test 3:56:30 AM'
*
* // Manually change the level
* logger.level = 3;
* ```
*/
export const consolaLogger = createConsola();
export const logger = consolaLogger;
if (process.env.CONSOLA_LOGGER_LEVEL !== undefined) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;
else consolaLogger.level = process.env.NODE_ENV === 'production' ? 0 : consolaLogger.level;
export default consolaLogger;