-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
84 lines (78 loc) · 2.21 KB
/
Copy pathindex.js
File metadata and controls
84 lines (78 loc) · 2.21 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @module logger
* @description - Module to customize built-in console functions improving logging features.
* @license MIT
* @autor Cris-Mur
*/
const boolean = require('#Utils/boolean');
const tag = require('./tag');
const util = require('node:util');
const raw_log = console.log;
/**
* @function logger
* @description - Overrides the default `console.log` with custom format.
* @param {...any} args - Arguments to be logged.
*/
function logger(...args) {
const level = "log";
const prefix = tag(level);
raw_log(prefix + applyFormat(...args));
}
console.log = logger;
const raw_error = console.error;
/**
* @function logger_error
* @description - Overrides the default `console.error`.
* @param {...any} args - Arguments to be logged as errors.
*/
function logger_error(...args) {
const level = "error";
const prefix = tag(level);
raw_error(prefix + applyFormat(...args));
}
console.error = logger_error;
const raw_debug = console.debug;
/**
* @function logger_debug
* @description - Overrides the default `console.debug`.
* @param {...any} args - Arguments to be logged as debug messages.
*/
function logger_debug(...args) {
if (!boolean(process.env.VERBOSE))
return;
const level = "debug";
const prefix = tag(level);
raw_debug(prefix + applyFormat(...args));
}
console.debug = logger_debug;
const raw_warn = console.warn;
/**
* @function logger_warn
* @description - Overrides the default `console.warn`.
* @param {...any} args - Arguments to be logged as warnings.
*/
function logger_warn(...args) {
if (!boolean(process.env.VERBOSE))
return;
const level = "warning";
const prefix = tag(level);
raw_warn(prefix + applyFormat(...args));
}
console.warn = logger_warn;
/**
* @function applyFormat
* @description - Function to handle format of input using core function.
* @param {...any} args - Input of console
* @returns {string} Formatted string with options.
*/
function applyFormat(...args) {
const formatOptions = {
colors: true
}
return util.formatWithOptions(formatOptions, ...args);
}
/**
* Exports the customized console with environment-aware logging and error handling.
* @namespace console
*/
module.exports = console;