-
Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathbasic.ts
44 lines (38 loc) · 1.35 KB
/
basic.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { LogLevels, LogLevel } from "./constants";
import type { ConsolaOptions } from "./types";
import { BasicReporter } from "./reporters/basic";
import { ConsolaInstance, createConsola as _createConsola } from "./consola";
export * from "./shared";
/**
* Factory function to create a new Consola instance
*
* @param {Partial<ConsolaOptions & { fancy: boolean }>} [options={}] - Optional configuration options. See {@link ConsolaOptions}.
* @returns {ConsolaInstance} A new Consola instance configured with the given options.
*/
export function createConsola(
options: Partial<ConsolaOptions & { fancy: boolean }> = {},
): ConsolaInstance {
// Log level
let level: LogLevel = LogLevels.info;
if (process.env.CONSOLA_LEVEL) {
level = Number.parseInt(process.env.CONSOLA_LEVEL) ?? level;
}
// Create new consola instance
const consola = _createConsola({
level,
defaults: { level },
stdout: process.stdout,
stderr: process.stderr,
reporters: options.reporters || [new BasicReporter()],
...options,
});
return consola;
}
/**
* Creates and exports a standard instance of Consola with the default configuration.
* This instance can be used directly for logging throughout the application.
*
* @type {ConsolaInstance} consola - The default instance of Consola.
*/
export const consola = createConsola();
export default consola;