node-ansi-logger 3.3.2-dev-20261101-706d6a5 → 3.3.2-dev-20261101-829a7db
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 +4 -0
- package/README.md +1 -1
- package/dist/ansi.js +1 -1
- package/dist/logger.d.ts +6 -6
- package/dist/logger.js +11 -13
- package/dist/stringify.js +4 -5
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -63,6 +63,10 @@ If you like this project and find it useful, please consider giving it a star on
|
|
|
63
63
|
|
|
64
64
|
### Fixed
|
|
65
65
|
|
|
66
|
+
- [logger]: Honor the NO_COLOR standard: any non-empty value (not only `1`) disables colors in the logger, ansi helpers and stringify.
|
|
67
|
+
- [logger]: `logFileSize` now returns `0` instead of `undefined` right after a log file path is set.
|
|
68
|
+
- [logger]: Correct typos in the timer stop message and the file-size limit message.
|
|
69
|
+
- [logger]: Correct the `setGlobalCallback` and `logTimeStampColor` JSDoc.
|
|
66
70
|
- [ansi]: Move the unsafe type assertion suppression to match the current lint diagnostic.
|
|
67
71
|
|
|
68
72
|
<a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="80"></a>
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ If you like this project and find it useful, please consider giving it a star on
|
|
|
24
24
|
- Simple and intuitive API for data logging.
|
|
25
25
|
- No dependencies.
|
|
26
26
|
- Customizable colors and apperance.
|
|
27
|
-
- Supports environment variable
|
|
27
|
+
- Supports the NO_COLOR environment variable (https://no-color.org/): any non-empty value disables colors.
|
|
28
28
|
- It is also possible to pass a top level logger (like Homebridge or Matter logger) and AnsiLogger will use it
|
|
29
29
|
for output instead of console.
|
|
30
30
|
- Includes also a fully customizable stringify funtion with colors (it is bigint aware and manage circular reference).
|
package/dist/ansi.js
CHANGED
|
@@ -118,7 +118,7 @@ function joinTemplate(strings, values) {
|
|
|
118
118
|
* @returns {string} ANSI-decorated text.
|
|
119
119
|
*/
|
|
120
120
|
function applyStyles(text, styles) {
|
|
121
|
-
if (
|
|
121
|
+
if (process.env.NO_COLOR)
|
|
122
122
|
return text;
|
|
123
123
|
let output = text;
|
|
124
124
|
for (const [open, close] of styles) {
|
package/dist/logger.d.ts
CHANGED
|
@@ -212,15 +212,15 @@ export declare class AnsiLogger {
|
|
|
212
212
|
*/
|
|
213
213
|
set logWithColors(logWithColors: boolean);
|
|
214
214
|
/**
|
|
215
|
-
* Gets the log
|
|
215
|
+
* Gets the log timestamp color string of the logger.
|
|
216
216
|
*
|
|
217
|
-
* @returns {string} The log
|
|
217
|
+
* @returns {string} The log timestamp color string.
|
|
218
218
|
*/
|
|
219
219
|
get logTimeStampColor(): string;
|
|
220
220
|
/**
|
|
221
|
-
* Sets the log
|
|
221
|
+
* Sets the log timestamp color string for the logger.
|
|
222
222
|
*
|
|
223
|
-
* @param {string} color - The
|
|
223
|
+
* @param {string} color - The log timestamp color string to set.
|
|
224
224
|
*/
|
|
225
225
|
set logTimeStampColor(color: string);
|
|
226
226
|
/**
|
|
@@ -336,9 +336,9 @@ export declare class AnsiLogger {
|
|
|
336
336
|
* Sets the global callback function to be used by the logger.
|
|
337
337
|
*
|
|
338
338
|
* @param {AnsiLoggerCallback | undefined} callback - The callback function.
|
|
339
|
-
* @param {LogLevel} [callbackLevel]
|
|
339
|
+
* @param {LogLevel} [callbackLevel] - The log level of the global callback (default LogLevel.DEBUG).
|
|
340
340
|
*
|
|
341
|
-
* @returns {AnsiLoggerCallback | undefined} The
|
|
341
|
+
* @returns {AnsiLoggerCallback | undefined} The callback function that was set.
|
|
342
342
|
*/
|
|
343
343
|
static setGlobalCallback(callback: AnsiLoggerCallback | undefined, callbackLevel?: LogLevel): AnsiLoggerCallback | undefined;
|
|
344
344
|
/**
|
package/dist/logger.js
CHANGED
|
@@ -151,7 +151,7 @@ export class AnsiLogger {
|
|
|
151
151
|
this.#logName = params.logName ?? 'NodeAnsiLogger';
|
|
152
152
|
this.#logNameColor = params.logNameColor ?? '[38;5;31m';
|
|
153
153
|
this.#logLevel = params.logLevel ?? "info" /* LogLevel.INFO */;
|
|
154
|
-
this.#logWithColors = params.logWithColors ?? process.env.NO_COLOR
|
|
154
|
+
this.#logWithColors = params.logWithColors ?? !process.env.NO_COLOR;
|
|
155
155
|
const envTimestampFormat = /^\d$/.test(process.env.NODE_ANSI_LOGGER_TIMESTAMP_FORMAT ?? '') ? Number(process.env.NODE_ANSI_LOGGER_TIMESTAMP_FORMAT) : undefined;
|
|
156
156
|
this.#logTimestampFormat = params.logTimestampFormat ?? (AnsiLogger.isTimestampFormat(envTimestampFormat) ? envTimestampFormat : 3 /* TimestampFormat.LOCAL_DATE_TIME */);
|
|
157
157
|
this.#logTimeStampColor = params.logTimeStampColor ?? '[38;5;245m';
|
|
@@ -253,17 +253,17 @@ export class AnsiLogger {
|
|
|
253
253
|
this.#logWithColors = logWithColors;
|
|
254
254
|
}
|
|
255
255
|
/**
|
|
256
|
-
* Gets the log
|
|
256
|
+
* Gets the log timestamp color string of the logger.
|
|
257
257
|
*
|
|
258
|
-
* @returns {string} The log
|
|
258
|
+
* @returns {string} The log timestamp color string.
|
|
259
259
|
*/
|
|
260
260
|
get logTimeStampColor() {
|
|
261
261
|
return this.#logTimeStampColor;
|
|
262
262
|
}
|
|
263
263
|
/**
|
|
264
|
-
* Sets the log
|
|
264
|
+
* Sets the log timestamp color string for the logger.
|
|
265
265
|
*
|
|
266
|
-
* @param {string} color - The
|
|
266
|
+
* @param {string} color - The log timestamp color string to set.
|
|
267
267
|
*/
|
|
268
268
|
set logTimeStampColor(color) {
|
|
269
269
|
this.#logTimeStampColor = color;
|
|
@@ -366,7 +366,7 @@ export class AnsiLogger {
|
|
|
366
366
|
* @returns {number | undefined} The size of log file, or undefined if not set.
|
|
367
367
|
*/
|
|
368
368
|
get logFileSize() {
|
|
369
|
-
return this.#logFilePath
|
|
369
|
+
return this.#logFilePath ? this.#logFileSize : undefined;
|
|
370
370
|
}
|
|
371
371
|
/**
|
|
372
372
|
* Gets the max file size of the file loggers.
|
|
@@ -409,7 +409,7 @@ export class AnsiLogger {
|
|
|
409
409
|
stopTimer(message) {
|
|
410
410
|
if (this.#logStartTime !== 0) {
|
|
411
411
|
const timePassed = Date.now() - this.#logStartTime;
|
|
412
|
-
this.info(`Timer
|
|
412
|
+
this.info(`Timer stopped at ${timePassed} ms ${message}`);
|
|
413
413
|
}
|
|
414
414
|
this.#logStartTime = 0;
|
|
415
415
|
}
|
|
@@ -451,9 +451,9 @@ export class AnsiLogger {
|
|
|
451
451
|
* Sets the global callback function to be used by the logger.
|
|
452
452
|
*
|
|
453
453
|
* @param {AnsiLoggerCallback | undefined} callback - The callback function.
|
|
454
|
-
* @param {LogLevel} [callbackLevel]
|
|
454
|
+
* @param {LogLevel} [callbackLevel] - The log level of the global callback (default LogLevel.DEBUG).
|
|
455
455
|
*
|
|
456
|
-
* @returns {AnsiLoggerCallback | undefined} The
|
|
456
|
+
* @returns {AnsiLoggerCallback | undefined} The callback function that was set.
|
|
457
457
|
*/
|
|
458
458
|
static setGlobalCallback(callback, callbackLevel = "debug" /* LogLevel.DEBUG */) {
|
|
459
459
|
__AnsiLoggerCallback__ = callback;
|
|
@@ -800,8 +800,7 @@ export class AnsiLogger {
|
|
|
800
800
|
const size = this.logToFile(this.logFilePath, level, message, ...parameters);
|
|
801
801
|
this.#logFileSize += size;
|
|
802
802
|
if (this.#logFileSize >= this.#maxFileSize) {
|
|
803
|
-
|
|
804
|
-
appendFileSync(this.logFilePath, `Logging on file has been stoppped because the file size is greater then ${this.#maxFileSize}B.\n`);
|
|
803
|
+
appendFileSync(this.logFilePath, `Logging on file has been stopped because the file size is greater than ${this.#maxFileSize}B.\n`);
|
|
805
804
|
}
|
|
806
805
|
}
|
|
807
806
|
}
|
|
@@ -818,8 +817,7 @@ export class AnsiLogger {
|
|
|
818
817
|
const size = this.logToFile(__AnsiLoggerFilePath__, level, message, ...parameters);
|
|
819
818
|
__AnsiLoggerFileLogSize__ += size;
|
|
820
819
|
if (__AnsiLoggerFileLogSize__ >= this.#maxFileSize) {
|
|
821
|
-
|
|
822
|
-
appendFileSync(__AnsiLoggerFilePath__, `Logging on file has been stoppped because the file size is greater then ${this.#maxFileSize}B.\n`);
|
|
820
|
+
appendFileSync(__AnsiLoggerFilePath__, `Logging on file has been stopped because the file size is greater than ${this.#maxFileSize}B.\n`);
|
|
823
821
|
}
|
|
824
822
|
}
|
|
825
823
|
}
|
package/dist/stringify.js
CHANGED
|
@@ -94,7 +94,7 @@ export function debugStringify(payload) {
|
|
|
94
94
|
* @returns {string} A string representation of the payload with colors and quotes.
|
|
95
95
|
*/
|
|
96
96
|
export function stringify(payload, enableColors = false, colorPayload = 252, colorKey = 250, colorString = 35, colorNumber = 220, colorBoolean = 159, colorUndefined = 1, keyQuote = '', stringQuote = "'", tab = 0, index = 0, seenObjects = new Set()) {
|
|
97
|
-
if (process.env.NO_COLOR
|
|
97
|
+
if (process.env.NO_COLOR)
|
|
98
98
|
enableColors = false;
|
|
99
99
|
if (payload === null)
|
|
100
100
|
return 'null';
|
|
@@ -123,7 +123,7 @@ export function stringify(payload, enableColors = false, colorPayload = 252, col
|
|
|
123
123
|
return `${clr(colorUndefined)}(function)${reset()}`;
|
|
124
124
|
// No Default
|
|
125
125
|
}
|
|
126
|
-
/* v8 ignore next */
|
|
126
|
+
/* v8 ignore next -- unreachable: only primitives reach formatScalar and every primitive typeof is handled above */
|
|
127
127
|
return `${clr(colorUndefined)}${String(value)}${reset()}`;
|
|
128
128
|
};
|
|
129
129
|
const isTrackable = typeof payload === 'object' && payload !== null;
|
|
@@ -156,7 +156,6 @@ export function stringify(payload, enableColors = false, colorPayload = 252, col
|
|
|
156
156
|
// @ts-expect-error -- The type of value is unknown, but we will handle it in the code below
|
|
157
157
|
newValue = value;
|
|
158
158
|
// console.log(typeof newValue, key, value);
|
|
159
|
-
/* v8 ignore next cause is unreachable code for typeof, but included for completeness */
|
|
160
159
|
if (value === null) {
|
|
161
160
|
newValue = `${clr(colorUndefined)}null${reset()}`;
|
|
162
161
|
}
|
|
@@ -188,10 +187,10 @@ export function stringify(payload, enableColors = false, colorPayload = 252, col
|
|
|
188
187
|
}
|
|
189
188
|
else if (typeof newValue === 'symbol') {
|
|
190
189
|
newValue = `${clr(colorString)}${String(newValue)}${reset()}`;
|
|
191
|
-
}
|
|
190
|
+
} /* v8 ignore start -- unreachable: every typeof result is handled above */
|
|
192
191
|
else {
|
|
193
192
|
throw new Error(`Unsupported type: ${typeof newValue}`);
|
|
194
|
-
}
|
|
193
|
+
} /* v8 ignore stop */
|
|
195
194
|
if (isArray) {
|
|
196
195
|
string += newValue;
|
|
197
196
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-ansi-logger",
|
|
3
|
-
"version": "3.3.2-dev-20261101-
|
|
3
|
+
"version": "3.3.2-dev-20261101-829a7db",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "node-ansi-logger",
|
|
9
|
-
"version": "3.3.2-dev-20261101-
|
|
9
|
+
"version": "3.3.2-dev-20261101-829a7db",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=22.13.0 <23.0.0 || >=24.0.0 <25.0.0 || >=26.0.0 <27.0.0"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-ansi-logger",
|
|
3
|
-
"version": "3.3.2-dev-20261101-
|
|
3
|
+
"version": "3.3.2-dev-20261101-829a7db",
|
|
4
4
|
"description": "Enhanced Ansi Color Logging and Stringify for Node.js in type script",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"license": "Apache-2.0",
|