@vvlad1973/simple-logger 1.2.2 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +149 -0
- package/README.md +91 -41
- package/dist/__test__/simple-logger.test.js +54 -101
- package/dist/__test__/simple-logger.test.js.map +1 -1
- package/dist/classes/simple-logger.d.ts +125 -0
- package/dist/classes/simple-logger.js +290 -0
- package/dist/classes/simple-logger.js.map +1 -0
- package/dist/constants/constants.d.ts +9 -0
- package/dist/constants/constants.js +10 -0
- package/dist/constants/constants.js.map +1 -0
- package/dist/helpers/helpers.d.ts +31 -0
- package/dist/helpers/helpers.js +81 -0
- package/dist/helpers/helpers.js.map +1 -0
- package/dist/helpers/validators.d.ts +17 -0
- package/dist/helpers/validators.js +27 -0
- package/dist/helpers/validators.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/types/simple-logger.types.d.ts +27 -0
- package/dist/types/simple-logger.types.js +2 -0
- package/dist/types/simple-logger.types.js.map +1 -0
- package/docs/assets/highlight.css +9 -2
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/SimpleLogger.html +27 -15
- package/docs/index.html +51 -22
- package/docs/interfaces/ExternalLogger.html +10 -0
- package/docs/interfaces/LogFn.html +1 -0
- package/docs/interfaces/LoggerOptions.html +5 -0
- package/docs/modules.html +1 -1
- package/docs/types/LoggerFactory.html +1 -0
- package/docs/types/LoggerLevel.html +1 -1
- package/docs/types/PreparedLogCall.html +1 -0
- package/docs/variables/LoggerLevels.html +1 -0
- package/package.json +20 -7
- package/src/__test__/simple-logger.test.ts +67 -55
- package/src/classes/simple-logger.ts +354 -0
- package/src/constants/constants.ts +9 -0
- package/src/helpers/helpers.ts +92 -0
- package/src/helpers/validators.ts +36 -0
- package/src/index.ts +7 -2
- package/src/types/simple-logger.types.ts +40 -0
- package/docs/media/index.html +0 -39
- package/docs/types/ExternalLogger.html +0 -1
- package/jsdoc.json +0 -14
- package/src/simple-logger.ts +0 -190
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A module for simple logging with various logging levels.
|
|
3
|
+
* @module SimpleLogger
|
|
4
|
+
*/
|
|
5
|
+
import { ExternalLogger, LogFn, LoggerFactory, LoggerLevel, LoggerOptions } from '../types/simple-logger.types.js';
|
|
6
|
+
export default class SimpleLogger {
|
|
7
|
+
private currentLevelIndex;
|
|
8
|
+
private logger;
|
|
9
|
+
private bindings;
|
|
10
|
+
private msgPrefix?;
|
|
11
|
+
private enabled;
|
|
12
|
+
isExternal: boolean;
|
|
13
|
+
static readonly noop: LogFn;
|
|
14
|
+
trace: LogFn;
|
|
15
|
+
debug: LogFn;
|
|
16
|
+
info: LogFn;
|
|
17
|
+
warn: LogFn;
|
|
18
|
+
error: LogFn;
|
|
19
|
+
fatal: LogFn;
|
|
20
|
+
silent: LogFn;
|
|
21
|
+
/**
|
|
22
|
+
* Initializes a new instance of the SimpleLogger class.
|
|
23
|
+
*
|
|
24
|
+
* @param {ExternalLogger | LoggerFactory | null} externalLogger - The external logger to use, or null to use the console.
|
|
25
|
+
* @param {LoggerOptions} [options={}] - Options for the logger, such as the logging level and bindings.
|
|
26
|
+
*/
|
|
27
|
+
constructor(externalLogger?: ExternalLogger | LoggerFactory | null, options?: LoggerOptions);
|
|
28
|
+
/**
|
|
29
|
+
* Resolves the effective logging level based on the provided logger and explicit level.
|
|
30
|
+
*
|
|
31
|
+
* @param {ExternalLogger | Console} logger - The logger to resolve the level for.
|
|
32
|
+
* @param {LoggerLevel} [explicitLevel] - The explicit logging level to use, if provided.
|
|
33
|
+
* @return {LoggerLevel} The resolved effective logging level.
|
|
34
|
+
*/
|
|
35
|
+
private resolveEffectiveLevel;
|
|
36
|
+
/**
|
|
37
|
+
* Initializes the logger with the provided external logger and options.
|
|
38
|
+
*
|
|
39
|
+
* Handles different cases for the external logger, including:
|
|
40
|
+
* - No external logger provided (falls back to console)
|
|
41
|
+
* - External logger is a factory function (e.g. pino)
|
|
42
|
+
* - External logger is invalid or console (falls back to console)
|
|
43
|
+
* - External logger is provided without parameters
|
|
44
|
+
* - External logger has a .child() method
|
|
45
|
+
* - External logger does not have a .child() method (uses directly)
|
|
46
|
+
*
|
|
47
|
+
* @param {ExternalLogger | LoggerFactory | null} externalLogger - The external logger to use, or null to use the console.
|
|
48
|
+
* @param {LoggerOptions} options - Options for the logger, such as the logging level and bindings.
|
|
49
|
+
* @return {void}
|
|
50
|
+
*/
|
|
51
|
+
private initLogger;
|
|
52
|
+
/**
|
|
53
|
+
* Updates the logging methods based on the current logging level and external logger configuration.
|
|
54
|
+
*
|
|
55
|
+
* Iterates over the available logging levels and sets the corresponding logging method to either call the external log method or the internal pretty format log method, depending on the logger configuration.
|
|
56
|
+
*
|
|
57
|
+
* @return {void}
|
|
58
|
+
*/
|
|
59
|
+
private updateLoggingMethods;
|
|
60
|
+
/**
|
|
61
|
+
* Calls the external log method for the specified level with the provided arguments.
|
|
62
|
+
*
|
|
63
|
+
* @param {LoggerLevel} level - The logging level to use for the external log method.
|
|
64
|
+
* @param {unknown[]} args - The arguments to pass to the external log method.
|
|
65
|
+
* @return {void}
|
|
66
|
+
*/
|
|
67
|
+
private callExternalLogMethod;
|
|
68
|
+
/**
|
|
69
|
+
* Formats and logs a message with the specified level and arguments.
|
|
70
|
+
*
|
|
71
|
+
* @param {LoggerLevel} level - The logging level to use for the log message.
|
|
72
|
+
* @param {unknown[]} args - The arguments to use when formatting the log message.
|
|
73
|
+
* @return {void}
|
|
74
|
+
*/
|
|
75
|
+
private prettyFormatLog;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves the current logging level.
|
|
78
|
+
*
|
|
79
|
+
* @return {LoggerLevel} The current logging level.
|
|
80
|
+
*/
|
|
81
|
+
getLevel(): LoggerLevel;
|
|
82
|
+
/**
|
|
83
|
+
* Sets the logging level.
|
|
84
|
+
*
|
|
85
|
+
* @param {LoggerLevel} level - The logging level to set.
|
|
86
|
+
* @return {void}
|
|
87
|
+
*/
|
|
88
|
+
setLevel(level: LoggerLevel): void;
|
|
89
|
+
/**
|
|
90
|
+
* Enables the logger.
|
|
91
|
+
*
|
|
92
|
+
* @return {void}
|
|
93
|
+
*/
|
|
94
|
+
enable(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Disables the logger.
|
|
97
|
+
*
|
|
98
|
+
* @return {void} Nothing is returned.
|
|
99
|
+
*/
|
|
100
|
+
disable(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new child logger with the merged bindings.
|
|
103
|
+
*
|
|
104
|
+
* If the external logger supports the `child` method, it will be used to create the child logger.
|
|
105
|
+
* Otherwise, a new SimpleLogger instance will be created with the merged bindings.
|
|
106
|
+
*
|
|
107
|
+
* @param {Record<string, unknown>} newBindings - The new bindings to merge with the existing bindings.
|
|
108
|
+
* @return {SimpleLogger} The new child logger instance.
|
|
109
|
+
*/
|
|
110
|
+
child(newBindings: Record<string, unknown>): SimpleLogger;
|
|
111
|
+
/**
|
|
112
|
+
* Logs the start of a function.
|
|
113
|
+
*
|
|
114
|
+
* @param {string} name - Optional function name to log. If not provided, the caller function name will be used.
|
|
115
|
+
* @return {void}
|
|
116
|
+
*/
|
|
117
|
+
logFunctionStart(name?: string): void;
|
|
118
|
+
/**
|
|
119
|
+
* Logs the end of a function.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} name - Optional function name to log. If not provided, the caller function name will be used.
|
|
122
|
+
* @return {void}
|
|
123
|
+
*/
|
|
124
|
+
logFunctionEnd(name?: string): void;
|
|
125
|
+
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A module for simple logging with various logging levels.
|
|
3
|
+
* @module SimpleLogger
|
|
4
|
+
*/
|
|
5
|
+
import util from 'util';
|
|
6
|
+
import { getCallerName } from 'vvlad1973-utils';
|
|
7
|
+
import { hasChild, isValidLogger } from '../helpers/validators.js';
|
|
8
|
+
import { extractContext, extractMessage, colorizeLevel, prepareLogCall, } from '../helpers/helpers.js';
|
|
9
|
+
import { LoggerLevels } from '../constants/constants.js';
|
|
10
|
+
export default class SimpleLogger {
|
|
11
|
+
currentLevelIndex = Object.values(LoggerLevels).indexOf(LoggerLevels.INFO);
|
|
12
|
+
logger = console;
|
|
13
|
+
bindings = {};
|
|
14
|
+
msgPrefix;
|
|
15
|
+
enabled = true;
|
|
16
|
+
isExternal = false;
|
|
17
|
+
static noop = () => { };
|
|
18
|
+
trace = SimpleLogger.noop;
|
|
19
|
+
debug = SimpleLogger.noop;
|
|
20
|
+
info = SimpleLogger.noop;
|
|
21
|
+
warn = SimpleLogger.noop;
|
|
22
|
+
error = SimpleLogger.noop;
|
|
23
|
+
fatal = SimpleLogger.noop;
|
|
24
|
+
silent = SimpleLogger.noop;
|
|
25
|
+
/**
|
|
26
|
+
* Initializes a new instance of the SimpleLogger class.
|
|
27
|
+
*
|
|
28
|
+
* @param {ExternalLogger | LoggerFactory | null} externalLogger - The external logger to use, or null to use the console.
|
|
29
|
+
* @param {LoggerOptions} [options={}] - Options for the logger, such as the logging level and bindings.
|
|
30
|
+
*/
|
|
31
|
+
constructor(externalLogger, options = {}) {
|
|
32
|
+
this.initLogger(externalLogger, options);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolves the effective logging level based on the provided logger and explicit level.
|
|
36
|
+
*
|
|
37
|
+
* @param {ExternalLogger | Console} logger - The logger to resolve the level for.
|
|
38
|
+
* @param {LoggerLevel} [explicitLevel] - The explicit logging level to use, if provided.
|
|
39
|
+
* @return {LoggerLevel} The resolved effective logging level.
|
|
40
|
+
*/
|
|
41
|
+
resolveEffectiveLevel(logger, explicitLevel) {
|
|
42
|
+
const levels = Object.values(LoggerLevels);
|
|
43
|
+
if (explicitLevel)
|
|
44
|
+
return explicitLevel;
|
|
45
|
+
if (logger &&
|
|
46
|
+
typeof logger === 'object' &&
|
|
47
|
+
'level' in logger &&
|
|
48
|
+
typeof logger.level === 'string') {
|
|
49
|
+
const lvl = logger.level.toLowerCase();
|
|
50
|
+
if (levels.includes(lvl))
|
|
51
|
+
return lvl;
|
|
52
|
+
}
|
|
53
|
+
return levels[this.currentLevelIndex];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Initializes the logger with the provided external logger and options.
|
|
57
|
+
*
|
|
58
|
+
* Handles different cases for the external logger, including:
|
|
59
|
+
* - No external logger provided (falls back to console)
|
|
60
|
+
* - External logger is a factory function (e.g. pino)
|
|
61
|
+
* - External logger is invalid or console (falls back to console)
|
|
62
|
+
* - External logger is provided without parameters
|
|
63
|
+
* - External logger has a .child() method
|
|
64
|
+
* - External logger does not have a .child() method (uses directly)
|
|
65
|
+
*
|
|
66
|
+
* @param {ExternalLogger | LoggerFactory | null} externalLogger - The external logger to use, or null to use the console.
|
|
67
|
+
* @param {LoggerOptions} options - Options for the logger, such as the logging level and bindings.
|
|
68
|
+
* @return {void}
|
|
69
|
+
*/
|
|
70
|
+
initLogger(externalLogger, options = {}) {
|
|
71
|
+
const { level, bindings = {}, msgPrefix, transport, ...restOptions } = options;
|
|
72
|
+
const hasParams = level || msgPrefix || Object.keys(bindings).length > 0;
|
|
73
|
+
const effectiveBindings = {
|
|
74
|
+
...bindings,
|
|
75
|
+
...(msgPrefix ? { msgPrefix } : {}),
|
|
76
|
+
};
|
|
77
|
+
this.bindings = effectiveBindings;
|
|
78
|
+
this.msgPrefix = msgPrefix;
|
|
79
|
+
// CASE 1: логгер не передан
|
|
80
|
+
if (!externalLogger) {
|
|
81
|
+
this.logger = console;
|
|
82
|
+
this.isExternal = false;
|
|
83
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
// CASE 2: логгер — фабрика (например, pino)
|
|
87
|
+
if (typeof externalLogger === 'function') {
|
|
88
|
+
this.logger = externalLogger({
|
|
89
|
+
level,
|
|
90
|
+
...restOptions,
|
|
91
|
+
...(transport ? { transport } : {}),
|
|
92
|
+
});
|
|
93
|
+
this.isExternal = true;
|
|
94
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// CASE 3: логгер есть, но он невалиден (нет методов)
|
|
98
|
+
if (!isValidLogger(externalLogger) || externalLogger === console) {
|
|
99
|
+
console.warn('Invalid or console logger passed, falling back to internal console.');
|
|
100
|
+
this.logger = console;
|
|
101
|
+
this.isExternal = false;
|
|
102
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// CASE 4: логгер передан без параметров
|
|
106
|
+
if (!hasParams) {
|
|
107
|
+
this.logger = externalLogger;
|
|
108
|
+
this.isExternal = true;
|
|
109
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
// CASE 5: логгер с .child()
|
|
113
|
+
if (hasChild(externalLogger)) {
|
|
114
|
+
this.logger = externalLogger.child({
|
|
115
|
+
...effectiveBindings,
|
|
116
|
+
...restOptions,
|
|
117
|
+
...(transport ? { transport } : {}),
|
|
118
|
+
});
|
|
119
|
+
this.isExternal = true;
|
|
120
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// CASE 6: логгер без .child — используем напрямую, только применим level
|
|
124
|
+
this.logger = externalLogger;
|
|
125
|
+
this.isExternal = true;
|
|
126
|
+
if (typeof externalLogger.level === 'string') {
|
|
127
|
+
externalLogger.level = this.resolveEffectiveLevel(this.logger, level);
|
|
128
|
+
}
|
|
129
|
+
this.setLevel(this.resolveEffectiveLevel(this.logger, level));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Updates the logging methods based on the current logging level and external logger configuration.
|
|
133
|
+
*
|
|
134
|
+
* Iterates over the available logging levels and sets the corresponding logging method to either call the external log method or the internal pretty format log method, depending on the logger configuration.
|
|
135
|
+
*
|
|
136
|
+
* @return {void}
|
|
137
|
+
*/
|
|
138
|
+
updateLoggingMethods() {
|
|
139
|
+
const levels = Object.values(LoggerLevels);
|
|
140
|
+
levels.forEach((level, index) => {
|
|
141
|
+
if (this.enabled && this.currentLevelIndex <= index) {
|
|
142
|
+
this[level] = (...args) => {
|
|
143
|
+
if (this.isExternal) {
|
|
144
|
+
this.callExternalLogMethod(level, args);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.prettyFormatLog(level, args);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
this[level] = SimpleLogger.noop;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Calls the external log method for the specified level with the provided arguments.
|
|
158
|
+
*
|
|
159
|
+
* @param {LoggerLevel} level - The logging level to use for the external log method.
|
|
160
|
+
* @param {unknown[]} args - The arguments to pass to the external log method.
|
|
161
|
+
* @return {void}
|
|
162
|
+
*/
|
|
163
|
+
callExternalLogMethod(level, args) {
|
|
164
|
+
const method = this.logger[level];
|
|
165
|
+
if (typeof method !== 'function')
|
|
166
|
+
return;
|
|
167
|
+
const prepared = prepareLogCall(args);
|
|
168
|
+
if (prepared !== null) {
|
|
169
|
+
method(...prepared);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
console.warn(`Invalid log arguments for "${level}"`, args);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Formats and logs a message with the specified level and arguments.
|
|
177
|
+
*
|
|
178
|
+
* @param {LoggerLevel} level - The logging level to use for the log message.
|
|
179
|
+
* @param {unknown[]} args - The arguments to use when formatting the log message.
|
|
180
|
+
* @return {void}
|
|
181
|
+
*/
|
|
182
|
+
prettyFormatLog(level, args) {
|
|
183
|
+
const time = new Date().toISOString().slice(0, 19).replace('T', ' ');
|
|
184
|
+
const levelStr = colorizeLevel(level, level.toUpperCase().padEnd(5));
|
|
185
|
+
const context = extractContext(args);
|
|
186
|
+
const { msg, rest } = extractMessage(args);
|
|
187
|
+
const fullMsg = util.format(msg, ...rest);
|
|
188
|
+
const ctx = Object.entries({ ...this.bindings, ...context })
|
|
189
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
190
|
+
.join(' ');
|
|
191
|
+
const prefix = `[${time}] ${levelStr}`;
|
|
192
|
+
const contextStr = ctx ? ` (${ctx})` : '';
|
|
193
|
+
const msgPrefixStr = this.msgPrefix ? ` ${this.msgPrefix}` : '';
|
|
194
|
+
console.log(`${prefix}${contextStr}:${msgPrefixStr} ${fullMsg}`);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Retrieves the current logging level.
|
|
198
|
+
*
|
|
199
|
+
* @return {LoggerLevel} The current logging level.
|
|
200
|
+
*/
|
|
201
|
+
getLevel() {
|
|
202
|
+
return Object.values(LoggerLevels)[this.currentLevelIndex];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Sets the logging level.
|
|
206
|
+
*
|
|
207
|
+
* @param {LoggerLevel} level - The logging level to set.
|
|
208
|
+
* @return {void}
|
|
209
|
+
*/
|
|
210
|
+
setLevel(level) {
|
|
211
|
+
const index = Object.values(LoggerLevels).indexOf(level);
|
|
212
|
+
if (index !== -1) {
|
|
213
|
+
this.currentLevelIndex = index;
|
|
214
|
+
if (typeof this.logger.level === 'string') {
|
|
215
|
+
this.logger.level = level;
|
|
216
|
+
}
|
|
217
|
+
this.updateLoggingMethods();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Enables the logger.
|
|
222
|
+
*
|
|
223
|
+
* @return {void}
|
|
224
|
+
*/
|
|
225
|
+
enable() {
|
|
226
|
+
this.enabled = true;
|
|
227
|
+
this.updateLoggingMethods();
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Disables the logger.
|
|
231
|
+
*
|
|
232
|
+
* @return {void} Nothing is returned.
|
|
233
|
+
*/
|
|
234
|
+
disable() {
|
|
235
|
+
this.enabled = false;
|
|
236
|
+
this.updateLoggingMethods();
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Creates a new child logger with the merged bindings.
|
|
240
|
+
*
|
|
241
|
+
* If the external logger supports the `child` method, it will be used to create the child logger.
|
|
242
|
+
* Otherwise, a new SimpleLogger instance will be created with the merged bindings.
|
|
243
|
+
*
|
|
244
|
+
* @param {Record<string, unknown>} newBindings - The new bindings to merge with the existing bindings.
|
|
245
|
+
* @return {SimpleLogger} The new child logger instance.
|
|
246
|
+
*/
|
|
247
|
+
child(newBindings) {
|
|
248
|
+
const merged = { ...this.bindings, ...newBindings };
|
|
249
|
+
if (this.isExternal &&
|
|
250
|
+
typeof this.logger === 'object' &&
|
|
251
|
+
this.logger !== null) {
|
|
252
|
+
const logger = this.logger;
|
|
253
|
+
const childFn = logger.child;
|
|
254
|
+
if (typeof childFn === 'function') {
|
|
255
|
+
const childLogger = childFn.call(logger, merged);
|
|
256
|
+
return new SimpleLogger(childLogger, {
|
|
257
|
+
level: this.getLevel(),
|
|
258
|
+
bindings: merged,
|
|
259
|
+
msgPrefix: this.msgPrefix,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return new SimpleLogger(this.logger, {
|
|
264
|
+
level: this.getLevel(),
|
|
265
|
+
bindings: merged,
|
|
266
|
+
msgPrefix: this.msgPrefix,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Logs the start of a function.
|
|
271
|
+
*
|
|
272
|
+
* @param {string} name - Optional function name to log. If not provided, the caller function name will be used.
|
|
273
|
+
* @return {void}
|
|
274
|
+
*/
|
|
275
|
+
logFunctionStart(name) {
|
|
276
|
+
const caller = name || getCallerName();
|
|
277
|
+
this.trace(`Function start: ${caller}`);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Logs the end of a function.
|
|
281
|
+
*
|
|
282
|
+
* @param {string} name - Optional function name to log. If not provided, the caller function name will be used.
|
|
283
|
+
* @return {void}
|
|
284
|
+
*/
|
|
285
|
+
logFunctionEnd(name) {
|
|
286
|
+
const caller = name || getCallerName();
|
|
287
|
+
this.trace(`Function end: ${caller}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=simple-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple-logger.js","sourceRoot":"","sources":["../../src/classes/simple-logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EACL,cAAc,EACd,cAAc,EACd,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AASzD,MAAM,CAAC,OAAO,OAAO,YAAY;IACvB,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,OAAO,CAC7D,YAAY,CAAC,IAAI,CAClB,CAAC;IACM,MAAM,GAA6B,OAAO,CAAC;IAC3C,QAAQ,GAA4B,EAAE,CAAC;IACvC,SAAS,CAAU;IACnB,OAAO,GAAG,IAAI,CAAC;IACvB,UAAU,GAAG,KAAK,CAAC;IAEnB,MAAM,CAAU,IAAI,GAAU,GAAG,EAAE,GAAE,CAAC,CAAC;IAEvC,KAAK,GAAU,YAAY,CAAC,IAAI,CAAC;IACjC,KAAK,GAAU,YAAY,CAAC,IAAI,CAAC;IACjC,IAAI,GAAU,YAAY,CAAC,IAAI,CAAC;IAChC,IAAI,GAAU,YAAY,CAAC,IAAI,CAAC;IAChC,KAAK,GAAU,YAAY,CAAC,IAAI,CAAC;IACjC,KA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M,GAAG,IAAI,IAAI,aAAa,EAAE,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACI,cAAc,CAAC,IAAa;QACjC,MAAM,MAAM,GAAG,IAAI,IAAI,aAAa,EAAE,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,iBAAiB,MAAM,EAAE,CAAC,CAAC;IACxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;CACR,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { LoggerLevel, PreparedLogCall } from '../types/simple-logger.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the message and rest of the arguments from the provided array.
|
|
4
|
+
*
|
|
5
|
+
* If the first argument is an object and the second argument is a string, the second argument is considered the message.
|
|
6
|
+
* If the first argument is a string, it is considered the message.
|
|
7
|
+
* Otherwise, an empty message is returned.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown[]} args - The array of arguments to extract the message from.
|
|
10
|
+
* @return {{ msg: string; rest: unknown[] }} An object containing the extracted message and the rest of the arguments.
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractMessage(args: unknown[]): {
|
|
13
|
+
msg: string;
|
|
14
|
+
rest: unknown[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Extracts the context object from the provided array of arguments.
|
|
18
|
+
*
|
|
19
|
+
* @param {unknown[]} args - The array of arguments to extract the context from.
|
|
20
|
+
* @return {Record<string, unknown>} The extracted context object, or an empty object if no context is found.
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractContext(args: unknown[]): Record<string, unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns a string with the provided label colored according to the specified logging level.
|
|
25
|
+
*
|
|
26
|
+
* @param {LoggerLevel} level - The logging level to determine the color from.
|
|
27
|
+
* @param {string} label - The label to be colored.
|
|
28
|
+
* @return {string} The colored label.
|
|
29
|
+
*/
|
|
30
|
+
export declare function colorizeLevel(level: LoggerLevel, label: string): string;
|
|
31
|
+
export declare function prepareLogCall(args: unknown[]): PreparedLogCall;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { LoggerLevels } from '../constants/constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extracts the message and rest of the arguments from the provided array.
|
|
5
|
+
*
|
|
6
|
+
* If the first argument is an object and the second argument is a string, the second argument is considered the message.
|
|
7
|
+
* If the first argument is a string, it is considered the message.
|
|
8
|
+
* Otherwise, an empty message is returned.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown[]} args - The array of arguments to extract the message from.
|
|
11
|
+
* @return {{ msg: string; rest: unknown[] }} An object containing the extracted message and the rest of the arguments.
|
|
12
|
+
*/
|
|
13
|
+
export function extractMessage(args) {
|
|
14
|
+
const [first, second, ...rest] = args;
|
|
15
|
+
if (typeof first === 'object' &&
|
|
16
|
+
first !== null &&
|
|
17
|
+
typeof second === 'string') {
|
|
18
|
+
return { msg: second, rest };
|
|
19
|
+
}
|
|
20
|
+
if (typeof first === 'string') {
|
|
21
|
+
return {
|
|
22
|
+
msg: first,
|
|
23
|
+
rest: [second, ...rest].filter((value) => value !== undefined),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return { msg: '', rest: [] };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Extracts the context object from the provided array of arguments.
|
|
30
|
+
*
|
|
31
|
+
* @param {unknown[]} args - The array of arguments to extract the context from.
|
|
32
|
+
* @return {Record<string, unknown>} The extracted context object, or an empty object if no context is found.
|
|
33
|
+
*/
|
|
34
|
+
export function extractContext(args) {
|
|
35
|
+
const [first] = args;
|
|
36
|
+
if (typeof first === 'object' && first !== null && !Array.isArray(first)) {
|
|
37
|
+
return first;
|
|
38
|
+
}
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns a string with the provided label colored according to the specified logging level.
|
|
43
|
+
*
|
|
44
|
+
* @param {LoggerLevel} level - The logging level to determine the color from.
|
|
45
|
+
* @param {string} label - The label to be colored.
|
|
46
|
+
* @return {string} The colored label.
|
|
47
|
+
*/
|
|
48
|
+
export function colorizeLevel(level, label) {
|
|
49
|
+
switch (level) {
|
|
50
|
+
case LoggerLevels.DEBUG:
|
|
51
|
+
case LoggerLevels.TRACE:
|
|
52
|
+
return chalk.gray(label);
|
|
53
|
+
case LoggerLevels.INFO:
|
|
54
|
+
return chalk.green(label);
|
|
55
|
+
case LoggerLevels.WARN:
|
|
56
|
+
return chalk.yellow(label);
|
|
57
|
+
case LoggerLevels.ERROR:
|
|
58
|
+
case LoggerLevels.FATAL:
|
|
59
|
+
return chalk.red(label);
|
|
60
|
+
default:
|
|
61
|
+
return label;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Prepares the log call by rearranging the provided arguments into a standardized format.
|
|
65
|
+
*
|
|
66
|
+
* @param {unknown[]} args - The array of arguments to prepare for the log call.
|
|
67
|
+
* @return {PreparedLogCall} The prepared log call arguments, or null if the input is invalid.
|
|
68
|
+
*/
|
|
69
|
+
}
|
|
70
|
+
export function prepareLogCall(args) {
|
|
71
|
+
if (typeof args[0] === 'string') {
|
|
72
|
+
return [args[0], ...args.slice(1)];
|
|
73
|
+
}
|
|
74
|
+
if (typeof args[0] === 'object' && args[0] !== null) {
|
|
75
|
+
const msg = typeof args[1] === 'string' ? args[1] : undefined;
|
|
76
|
+
const rest = args.slice(msg ? 2 : 1);
|
|
77
|
+
return [args[0], msg, ...rest];
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,IAAe;IAI5C,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAEtC,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,MAAM,KAAK,QAAQ,EAC1B,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC/B,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO;YACL,GAAG,EAAE,KAAK;YACV,IAAI,EAAE,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC;SAC/D,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAC/B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAe;IAC5C,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACrB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzE,OAAO,KAAgC,CAAC;IAC1C,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;;GAMG;AACH,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C;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ExternalLogger } from '../types/simple-logger.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the provided logger is a valid ExternalLogger instance.
|
|
4
|
+
*
|
|
5
|
+
* @param {unknown} logger - The logger to validate.
|
|
6
|
+
* @return {logger is ExternalLogger} True if the logger is a valid ExternalLogger, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isValidLogger(logger: unknown): logger is ExternalLogger;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the provided logger is an ExternalLogger instance with a child method.
|
|
11
|
+
*
|
|
12
|
+
* @param {unknown} logger - The logger to check.
|
|
13
|
+
* @return {logger is ExternalLogger & { child: Function }} True if the logger is an ExternalLogger with a child method, false otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export declare function hasChild(logger: unknown): logger is ExternalLogger & {
|
|
16
|
+
child: Function;
|
|
17
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { LoggerLevels } from '../constants/constants';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the provided logger is a valid ExternalLogger instance.
|
|
4
|
+
*
|
|
5
|
+
* @param {unknown} logger - The logger to validate.
|
|
6
|
+
* @return {logger is ExternalLogger} True if the logger is a valid ExternalLogger, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export function isValidLogger(logger) {
|
|
9
|
+
const levels = Object.values(LoggerLevels);
|
|
10
|
+
if (typeof logger !== 'object' || logger === null) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const candidate = logger;
|
|
14
|
+
return levels.some((level) => typeof candidate[level] === 'function');
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the provided logger is an ExternalLogger instance with a child method.
|
|
18
|
+
*
|
|
19
|
+
* @param {unknown} logger - The logger to check.
|
|
20
|
+
* @return {logger is ExternalLogger & { child: Function }} True if the logger is an ExternalLogger with a child method, false otherwise.
|
|
21
|
+
*/
|
|
22
|
+
export function hasChild(logger) {
|
|
23
|
+
return (typeof logger === 'object' &&
|
|
24
|
+
logger !== null &&
|
|
25
|
+
typeof logger.child === 'function');
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/helpers/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,MAAe;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAE3C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,SAAS,GAAG,MAAiC,CAAC;IAEpD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,UAAU,CAAC,CAAC;AACxE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CACtB,MAAe;IAEf,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,OAAQ,MAAc,CAAC,KAAK,KAAK,UAAU,CAC5C,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import SimpleLogger from './classes/simple-logger';
|
|
2
|
+
export default SimpleLogger;
|
|
3
|
+
export { SimpleLogger };
|
|
4
|
+
export * from './types/simple-logger.types.js';
|
|
5
|
+
export * from './constants/constants.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import SimpleLogger from './classes/simple-logger';
|
|
2
|
+
export default SimpleLogger;
|
|
3
|
+
export { SimpleLogger };
|
|
4
|
+
export * from './types/simple-logger.types.js';
|
|
5
|
+
export * from './constants/constants.js';
|
|
3
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,yBAAyB,CAAC;AAEnD,eAAe,YAAY,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC"}
|