@vvlad1973/simple-logger 2.1.7 → 2.1.8
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 +173 -173
- package/dist/__test__/simple-logger.test.js +65 -65
- package/dist/classes/simple-logger.d.ts +125 -125
- package/dist/classes/simple-logger.js +294 -289
- package/dist/classes/simple-logger.js.map +1 -1
- package/dist/constants/constants.d.ts +9 -9
- package/dist/constants/constants.js +9 -9
- package/dist/helpers/helpers.d.ts +31 -31
- package/dist/helpers/helpers.js +80 -80
- package/dist/helpers/validators.d.ts +17 -17
- package/dist/helpers/validators.js +26 -26
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/simple-logger.d.ts +80 -80
- package/dist/simple-logger.js +151 -151
- package/dist/types/simple-logger.types.d.ts +33 -33
- package/dist/types/simple-logger.types.js +1 -1
- package/docs/assets/highlight.css +85 -85
- package/docs/assets/icons.js +17 -17
- package/docs/assets/main.js +60 -60
- package/docs/assets/style.css +1611 -1611
- package/docs/classes/SimpleLogger.html +37 -37
- package/docs/index.html +68 -68
- package/docs/interfaces/ExternalLogger.html +10 -10
- package/docs/interfaces/LogFn.html +1 -1
- package/docs/interfaces/LoggerOptions.html +5 -5
- package/docs/modules.html +1 -1
- package/docs/types/LoggerFactory.html +1 -1
- package/docs/types/LoggerLevel.html +1 -1
- package/docs/types/PreparedLogCall.html +1 -1
- package/docs/variables/LoggerLevels.html +1 -1
- package/package.json +7 -7
- package/src/classes/simple-logger.ts +19 -8
- package/src/types/simple-logger.types.ts +1 -1
|
@@ -1,125 +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
|
-
}
|
|
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
|
+
}
|