node-ansi-logger 3.3.2-dev-20261024-45fad9d → 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 CHANGED
@@ -25,6 +25,7 @@ If you like this project and find it useful, please consider giving it a star on
25
25
 
26
26
  ### Added
27
27
 
28
+ - [logger]: Add `AnsiLogger.isLogLevel()` and `AnsiLogger.isTimestampFormat()` static type guard helpers.
28
29
  - [logger]: Add an opt-in global circular message cache with configurable capacity, snapshots, callback replay, clearing and static setter/getter.
29
30
  - [devcontainer]: Add [`Dev Container`](.devcontainer/README.md) v.2.2.0 with dual Node and Bun runtime support.
30
31
  - [agents]: Add a [`shared setup`](.agents/README.md) for all agents: OpenAI Codex, Claude Code, GitHub Copilot and Google Gemini / Antigravity.
@@ -32,21 +33,40 @@ If you like this project and find it useful, please consider giving it a star on
32
33
 
33
34
  ### Changed
34
35
 
35
- - [vscode]: Update `.vscode/settings.json` to v.1.0.15.
36
+ - [logger]: BREAKING: Remove the deprecated `logDebug` constructor option. Use `logLevel` instead.
37
+ - [vscode]: Update `.vscode/settings.json` to v.1.0.17.
36
38
  - [config]: Update Oxlint and Oxfmt configurations to v.1.1.0 and Antigravity settings to v.1.0.5.
37
39
  - [config]: Update TypeScript build configurations and rename `vite.config.ts` to `vitest.config.ts`, including CI workflow detection.
38
40
  - [styleguide]: Update [`STYLEGUIDE.md`](STYLEGUIDE.md) to v.1.1.0: align it with the lint and format config and add the Commit Messages and Changelog sections.
39
41
  - [scripts]: Update scripts to v.2.0.0.
40
42
  - [package]: Upgrade package.
41
- - [package]: Bump `oxfmt` to v.0.74.0.
42
- - [package]: Bump `oxlint` to v.1.89.0.
43
+ - [package]: Bump `oxfmt` to v.0.75.0.
44
+ - [package]: Bump `oxlint` to v.1.90.0.
43
45
  - [package]: Bump `oxlint-tsgolint` to v.7.0.2004.
44
46
  - [package]: Bump `vitest` to v.5.0.5.
45
47
  - [package]: Bump `@vitest/coverage-v8` to v.5.0.5.
46
- - [package]: Bump `@types/node` to v.26.6.5.
48
+ - [package]: Bump `@types/node` to v.26.6.6.
49
+ - [codex]: Update `.codex/config.toml` to v.1.0.6.
50
+ - [agents]: Update `.github/commit-message-instructions.md` to v.1.0.1.
51
+ - [vscode]: Update `.vscode/tasks.json`.
52
+ - [agents]: Update `AGENTS.md` to v.1.0.8.
53
+ - [config]: Update `CODE_OF_CONDUCT.md` to v.1.0.0.
54
+ - [config]: Update `CONTRIBUTING.md` to v.1.0.1.
55
+ - [scripts]: Update `scripts/downloads.mjs`.
56
+ - [scripts]: Update `scripts/git-sync-dev.mjs`.
57
+ - [config]: Update `src/logger.ts`.
58
+ - [config]: Update `vitest/cache.test.ts`.
59
+ - [config]: Update `vitest/logger.branchcoverage.test.ts`.
60
+ - [config]: Update `vitest/logger.test.ts`.
61
+ - [config]: Add `SHARED-AGENTS.md`.
62
+ - [config]: Add `TOOLCHAIN.md` v.1.0.1.
47
63
 
48
64
  ### Fixed
49
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.
50
70
  - [ansi]: Move the unsafe type assertion suppression to match the current lint diagnostic.
51
71
 
52
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 NO_COLOR=1 (https://no-color.org/).
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 ('NO_COLOR' in process.env)
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
@@ -106,10 +106,6 @@ export interface AnsiLoggerParams {
106
106
  extLog?: Logger;
107
107
  logName?: string;
108
108
  logNameColor?: string;
109
- /**
110
- * @deprecated Use logLevel instead.
111
- */
112
- logDebug?: boolean;
113
109
  logLevel?: LogLevel;
114
110
  logWithColors?: boolean;
115
111
  logTimestampFormat?: TimestampFormat;
@@ -165,6 +161,20 @@ export declare class AnsiLogger {
165
161
  * AnsiLogger.create({ logName: 'MyLogger' }).info('This is a info message');
166
162
  */
167
163
  static create(params: AnsiLoggerParams): AnsiLogger;
164
+ /**
165
+ * Checks whether a value is a valid LogLevel.
166
+ *
167
+ * @param {unknown} value - The value to check.
168
+ * @returns {value is LogLevel} True if the value is one of the LogLevel values.
169
+ */
170
+ static isLogLevel(value: unknown): value is LogLevel;
171
+ /**
172
+ * Checks whether a value is a valid TimestampFormat.
173
+ *
174
+ * @param {unknown} value - The value to check.
175
+ * @returns {value is TimestampFormat} True if the value is one of the TimestampFormat values.
176
+ */
177
+ static isTimestampFormat(value: unknown): value is TimestampFormat;
168
178
  /**
169
179
  * Gets the name of the logger.
170
180
  *
@@ -202,15 +212,15 @@ export declare class AnsiLogger {
202
212
  */
203
213
  set logWithColors(logWithColors: boolean);
204
214
  /**
205
- * Gets the log name color string of the logger.
215
+ * Gets the log timestamp color string of the logger.
206
216
  *
207
- * @returns {string} The log name color string.
217
+ * @returns {string} The log timestamp color string.
208
218
  */
209
219
  get logTimeStampColor(): string;
210
220
  /**
211
- * Sets the log name color string for the logger.
221
+ * Sets the log timestamp color string for the logger.
212
222
  *
213
- * @param {string} color - The logger name color string to set.
223
+ * @param {string} color - The log timestamp color string to set.
214
224
  */
215
225
  set logTimeStampColor(color: string);
216
226
  /**
@@ -326,9 +336,9 @@ export declare class AnsiLogger {
326
336
  * Sets the global callback function to be used by the logger.
327
337
  *
328
338
  * @param {AnsiLoggerCallback | undefined} callback - The callback function.
329
- * @param {LogLevel} [callbackLevel] - The log level of the log file (default LogLevel.DEBUG).
339
+ * @param {LogLevel} [callbackLevel] - The log level of the global callback (default LogLevel.DEBUG).
330
340
  *
331
- * @returns {AnsiLoggerCallback | undefined} The path name of the log file.
341
+ * @returns {AnsiLoggerCallback | undefined} The callback function that was set.
332
342
  */
333
343
  static setGlobalCallback(callback: AnsiLoggerCallback | undefined, callbackLevel?: LogLevel): AnsiLoggerCallback | undefined;
334
344
  /**
package/dist/logger.js CHANGED
@@ -150,16 +150,10 @@ export class AnsiLogger {
150
150
  this.#extLog = params.extLog;
151
151
  this.#logName = params.logName ?? 'NodeAnsiLogger';
152
152
  this.#logNameColor = params.logNameColor ?? '';
153
- // oxlint-disable-next-line @typescript-eslint/no-deprecated
154
- this.#logLevel = params.logLevel ?? (params.logDebug === true ? "debug" /* LogLevel.DEBUG */ : "info" /* LogLevel.INFO */);
155
- this.#logWithColors = params.logWithColors ?? process.env.NO_COLOR !== '1';
156
- this.#logTimestampFormat =
157
- // oxlint-disable-next-line typescript/prefer-nullish-coalescing
158
- params.logTimestampFormat !== undefined
159
- ? params.logTimestampFormat
160
- : process.env.NODE_ANSI_LOGGER_TIMESTAMP_FORMAT !== undefined && ['0', '1', '2', '3', '4', '5', '6'].includes(process.env.NODE_ANSI_LOGGER_TIMESTAMP_FORMAT)
161
- ? Number(process.env.NODE_ANSI_LOGGER_TIMESTAMP_FORMAT)
162
- : 3 /* TimestampFormat.LOCAL_DATE_TIME */;
153
+ this.#logLevel = params.logLevel ?? "info" /* LogLevel.INFO */;
154
+ this.#logWithColors = params.logWithColors ?? !process.env.NO_COLOR;
155
+ const envTimestampFormat = /^\d$/.test(process.env.NODE_ANSI_LOGGER_TIMESTAMP_FORMAT ?? '') ? Number(process.env.NODE_ANSI_LOGGER_TIMESTAMP_FORMAT) : undefined;
156
+ this.#logTimestampFormat = params.logTimestampFormat ?? (AnsiLogger.isTimestampFormat(envTimestampFormat) ? envTimestampFormat : 3 /* TimestampFormat.LOCAL_DATE_TIME */);
163
157
  this.#logTimeStampColor = params.logTimeStampColor ?? '';
164
158
  this.#logCustomTimestampFormat =
165
159
  params.logCustomTimestampFormat !== undefined && typeof params.logCustomTimestampFormat === 'string'
@@ -182,6 +176,34 @@ export class AnsiLogger {
182
176
  static create(params) {
183
177
  return new AnsiLogger(params);
184
178
  }
179
+ /**
180
+ * Checks whether a value is a valid LogLevel.
181
+ *
182
+ * @param {unknown} value - The value to check.
183
+ * @returns {value is LogLevel} True if the value is one of the LogLevel values.
184
+ */
185
+ static isLogLevel(value) {
186
+ const levels = ["debug" /* LogLevel.DEBUG */, "info" /* LogLevel.INFO */, "notice" /* LogLevel.NOTICE */, "warn" /* LogLevel.WARN */, "error" /* LogLevel.ERROR */, "fatal" /* LogLevel.FATAL */, "" /* LogLevel.NONE */];
187
+ return typeof value === 'string' && levels.includes(value);
188
+ }
189
+ /**
190
+ * Checks whether a value is a valid TimestampFormat.
191
+ *
192
+ * @param {unknown} value - The value to check.
193
+ * @returns {value is TimestampFormat} True if the value is one of the TimestampFormat values.
194
+ */
195
+ static isTimestampFormat(value) {
196
+ const formats = [
197
+ 0 /* TimestampFormat.ISO */,
198
+ 1 /* TimestampFormat.LOCAL_DATE */,
199
+ 2 /* TimestampFormat.LOCAL_TIME */,
200
+ 3 /* TimestampFormat.LOCAL_DATE_TIME */,
201
+ 4 /* TimestampFormat.TIME_MILLIS */,
202
+ 5 /* TimestampFormat.HOMEBRIDGE */,
203
+ 6 /* TimestampFormat.CUSTOM */,
204
+ ];
205
+ return typeof value === 'number' && formats.includes(value);
206
+ }
185
207
  /**
186
208
  * Gets the name of the logger.
187
209
  *
@@ -231,17 +253,17 @@ export class AnsiLogger {
231
253
  this.#logWithColors = logWithColors;
232
254
  }
233
255
  /**
234
- * Gets the log name color string of the logger.
256
+ * Gets the log timestamp color string of the logger.
235
257
  *
236
- * @returns {string} The log name color string.
258
+ * @returns {string} The log timestamp color string.
237
259
  */
238
260
  get logTimeStampColor() {
239
261
  return this.#logTimeStampColor;
240
262
  }
241
263
  /**
242
- * Sets the log name color string for the logger.
264
+ * Sets the log timestamp color string for the logger.
243
265
  *
244
- * @param {string} color - The logger name color string to set.
266
+ * @param {string} color - The log timestamp color string to set.
245
267
  */
246
268
  set logTimeStampColor(color) {
247
269
  this.#logTimeStampColor = color;
@@ -344,7 +366,7 @@ export class AnsiLogger {
344
366
  * @returns {number | undefined} The size of log file, or undefined if not set.
345
367
  */
346
368
  get logFileSize() {
347
- return this.#logFilePath && this.#logFileSize ? this.#logFileSize : undefined;
369
+ return this.#logFilePath ? this.#logFileSize : undefined;
348
370
  }
349
371
  /**
350
372
  * Gets the max file size of the file loggers.
@@ -387,7 +409,7 @@ export class AnsiLogger {
387
409
  stopTimer(message) {
388
410
  if (this.#logStartTime !== 0) {
389
411
  const timePassed = Date.now() - this.#logStartTime;
390
- this.info(`Timer stoppped at ${timePassed} ms ${message}`);
412
+ this.info(`Timer stopped at ${timePassed} ms ${message}`);
391
413
  }
392
414
  this.#logStartTime = 0;
393
415
  }
@@ -429,9 +451,9 @@ export class AnsiLogger {
429
451
  * Sets the global callback function to be used by the logger.
430
452
  *
431
453
  * @param {AnsiLoggerCallback | undefined} callback - The callback function.
432
- * @param {LogLevel} [callbackLevel] - The log level of the log file (default LogLevel.DEBUG).
454
+ * @param {LogLevel} [callbackLevel] - The log level of the global callback (default LogLevel.DEBUG).
433
455
  *
434
- * @returns {AnsiLoggerCallback | undefined} The path name of the log file.
456
+ * @returns {AnsiLoggerCallback | undefined} The callback function that was set.
435
457
  */
436
458
  static setGlobalCallback(callback, callbackLevel = "debug" /* LogLevel.DEBUG */) {
437
459
  __AnsiLoggerCallback__ = callback;
@@ -778,8 +800,7 @@ export class AnsiLogger {
778
800
  const size = this.logToFile(this.logFilePath, level, message, ...parameters);
779
801
  this.#logFileSize += size;
780
802
  if (this.#logFileSize >= this.#maxFileSize) {
781
- /* v8 ignore next */
782
- 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`);
783
804
  }
784
805
  }
785
806
  }
@@ -796,8 +817,7 @@ export class AnsiLogger {
796
817
  const size = this.logToFile(__AnsiLoggerFilePath__, level, message, ...parameters);
797
818
  __AnsiLoggerFileLogSize__ += size;
798
819
  if (__AnsiLoggerFileLogSize__ >= this.#maxFileSize) {
799
- /* v8 ignore next */
800
- 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`);
801
821
  }
802
822
  }
803
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 === '1')
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
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "node-ansi-logger",
3
- "version": "3.3.2-dev-20261024-45fad9d",
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-20261024-45fad9d",
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-20261024-45fad9d",
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",