@ncoderz/log-m8 1.2.2 → 1.2.4
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/dist/browser/log-m8.global.js +1 -1
- package/dist/browser/log-m8.global.js.map +1 -1
- package/dist/index.cjs +70 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -3
- package/dist/index.d.ts +32 -3
- package/dist/index.js +69 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -239,7 +239,7 @@ interface Log {
|
|
|
239
239
|
*
|
|
240
240
|
* @param level - New logging level name (e.g., 'info', 'debug', 'off')
|
|
241
241
|
*/
|
|
242
|
-
setLevel(level: LogLevelType): void;
|
|
242
|
+
setLevel(level: string | LogLevelType): void;
|
|
243
243
|
/**
|
|
244
244
|
* Replaces the logger's contextual data.
|
|
245
245
|
*
|
|
@@ -484,6 +484,11 @@ interface PluginFactory<C extends PluginConfig = PluginConfig, P extends Plugin
|
|
|
484
484
|
create(config: C): P;
|
|
485
485
|
}
|
|
486
486
|
|
|
487
|
+
/**
|
|
488
|
+
* LogM8 - Central logging manager for TypeScript/JavaScript
|
|
489
|
+
*
|
|
490
|
+
*/
|
|
491
|
+
|
|
487
492
|
/**
|
|
488
493
|
* Central logging manager providing hierarchical loggers and configurable output.
|
|
489
494
|
*
|
|
@@ -614,7 +619,7 @@ declare class LogM8$1 {
|
|
|
614
619
|
* @param level - New logging level name (e.g., 'info', 'debug', 'off')
|
|
615
620
|
* @param logger - Optional logger name to set level for a specific logger
|
|
616
621
|
*/
|
|
617
|
-
setLevel(level: LogLevelType, logger?: string): void;
|
|
622
|
+
setLevel(level: string | LogLevelType, logger?: string): void;
|
|
618
623
|
/**
|
|
619
624
|
* Enables an appender to resume processing log events.
|
|
620
625
|
*
|
|
@@ -1275,6 +1280,30 @@ declare class LogM8Utils {
|
|
|
1275
1280
|
static parseRegexFromString(regex: string, extraFlags?: string[]): RegExp | undefined;
|
|
1276
1281
|
}
|
|
1277
1282
|
|
|
1283
|
+
declare class NullLogger implements Log {
|
|
1284
|
+
fatal(_message: string, ..._args: unknown[]): void;
|
|
1285
|
+
error(_message: string, ..._args: unknown[]): void;
|
|
1286
|
+
warn(_message: string, ..._args: unknown[]): void;
|
|
1287
|
+
info(_message: string, ..._args: unknown[]): void;
|
|
1288
|
+
debug(_message: string, ..._args: unknown[]): void;
|
|
1289
|
+
track(_message: string, ..._args: unknown[]): void;
|
|
1290
|
+
trace(_message: string, ..._args: unknown[]): void;
|
|
1291
|
+
readonly isFatal = false;
|
|
1292
|
+
readonly isError = false;
|
|
1293
|
+
readonly isWarn = false;
|
|
1294
|
+
readonly isInfo = false;
|
|
1295
|
+
readonly isDebug = false;
|
|
1296
|
+
readonly isTrack = false;
|
|
1297
|
+
readonly isTrace = false;
|
|
1298
|
+
readonly isEnabled = false;
|
|
1299
|
+
readonly name = "nullLogger";
|
|
1300
|
+
readonly level = "off";
|
|
1301
|
+
readonly context: LogContext;
|
|
1302
|
+
setLevel(_level: LogLevelType): void;
|
|
1303
|
+
setContext(context: LogContext): void;
|
|
1304
|
+
getLogger(_name: string): Log;
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1278
1307
|
/**
|
|
1279
1308
|
* Default singleton instance of the LogM8 logging manager.
|
|
1280
1309
|
*
|
|
@@ -1295,4 +1324,4 @@ declare class LogM8Utils {
|
|
|
1295
1324
|
*/
|
|
1296
1325
|
declare const LogM8: LogM8$1;
|
|
1297
1326
|
|
|
1298
|
-
export { type Appender, type AppenderConfig, type ConsoleAppenderConfig, type DefaultFormatterConfig, type FileAppenderConfig, type Filter, type FilterConfig, type Formatter, type FormatterConfig, type Log, type LogContext, LogLevel, type LogLevelType, LogM8, LogM8Utils, type LoggingConfig, type MatchFilterConfig, type Plugin, type PluginConfig, type PluginFactory, PluginKind, type PluginKindType };
|
|
1327
|
+
export { type Appender, type AppenderConfig, type ConsoleAppenderConfig, type DefaultFormatterConfig, type FileAppenderConfig, type Filter, type FilterConfig, type Formatter, type FormatterConfig, type Log, type LogContext, LogLevel, type LogLevelType, LogM8, LogM8Utils, type LoggingConfig, type MatchFilterConfig, NullLogger, type Plugin, type PluginConfig, type PluginFactory, PluginKind, type PluginKindType };
|
package/dist/index.js
CHANGED
|
@@ -566,20 +566,34 @@ var FileAppender = class {
|
|
|
566
566
|
__publicField(this, "_formatter");
|
|
567
567
|
__publicField(this, "_filters", []);
|
|
568
568
|
__publicField(this, "_stream");
|
|
569
|
+
__publicField(this, "_streamCreationFailed", false);
|
|
569
570
|
}
|
|
570
571
|
init(config, formatter, filters) {
|
|
571
572
|
this._config = config;
|
|
572
573
|
this._formatter = formatter;
|
|
573
574
|
this._filters = filters || [];
|
|
574
|
-
const flags = this._config.append ? "a" : "w";
|
|
575
|
-
this._stream = createWriteStream(this._config.filename ?? DEFAULT_FILENAME, { flags });
|
|
576
575
|
this.enabled = this._config?.enabled !== false;
|
|
577
576
|
this.priority = this._config?.priority;
|
|
577
|
+
if (this.enabled) {
|
|
578
|
+
this._createStream();
|
|
579
|
+
}
|
|
578
580
|
}
|
|
579
581
|
dispose() {
|
|
580
582
|
this._stream?.end();
|
|
583
|
+
this._stream = void 0;
|
|
581
584
|
}
|
|
582
585
|
write(event) {
|
|
586
|
+
if (this._streamCreationFailed) return;
|
|
587
|
+
if (!this._stream) {
|
|
588
|
+
try {
|
|
589
|
+
this._createStream();
|
|
590
|
+
} catch (err) {
|
|
591
|
+
if (console && console.error) {
|
|
592
|
+
console.error(`LogM8 [FileAppender]: Failed to create file stream: ${err}`);
|
|
593
|
+
}
|
|
594
|
+
this._streamCreationFailed = true;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
583
597
|
if (!this._stream) return;
|
|
584
598
|
for (const filter of this._filters) {
|
|
585
599
|
if (filter.enabled && !filter.filter(event)) {
|
|
@@ -608,6 +622,10 @@ var FileAppender = class {
|
|
|
608
622
|
_getFilter(name) {
|
|
609
623
|
return this._filters.find((f) => f.name === name);
|
|
610
624
|
}
|
|
625
|
+
_createStream() {
|
|
626
|
+
const flags = this._config?.append ? "a" : "w";
|
|
627
|
+
this._stream = createWriteStream(this._config?.filename ?? DEFAULT_FILENAME, { flags });
|
|
628
|
+
}
|
|
611
629
|
};
|
|
612
630
|
var FileAppenderFactory = class {
|
|
613
631
|
constructor() {
|
|
@@ -1108,12 +1126,11 @@ var LogM8 = class {
|
|
|
1108
1126
|
init(config) {
|
|
1109
1127
|
config = Object.assign({}, config);
|
|
1110
1128
|
this._reset();
|
|
1111
|
-
|
|
1112
|
-
this._globalLogLevel = this._logLevelSet.has(levelStr) ? levelStr : LogLevel.info;
|
|
1129
|
+
this.setLevel(config.level ?? LogLevel.info);
|
|
1113
1130
|
for (const [name, l] of Object.entries(config.loggers ?? {})) {
|
|
1114
|
-
const
|
|
1131
|
+
const levelStr = (l ?? "").trim().toLowerCase();
|
|
1115
1132
|
const logger = this.getLogger(name);
|
|
1116
|
-
const level = this._logLevelSet.has(
|
|
1133
|
+
const level = this._logLevelSet.has(levelStr) ? levelStr : this._globalLogLevel;
|
|
1117
1134
|
logger.setLevel(level);
|
|
1118
1135
|
}
|
|
1119
1136
|
const appenderConfigs = config.appenders ?? DEFAULT_APPENDERS;
|
|
@@ -1245,10 +1262,11 @@ var LogM8 = class {
|
|
|
1245
1262
|
* @param logger - Optional logger name to set level for a specific logger
|
|
1246
1263
|
*/
|
|
1247
1264
|
setLevel(level, logger) {
|
|
1265
|
+
const levelStr = (level ?? "").trim().toLowerCase();
|
|
1248
1266
|
if (logger) {
|
|
1249
|
-
this.getLogger(logger).setLevel(
|
|
1267
|
+
this.getLogger(logger).setLevel(levelStr);
|
|
1250
1268
|
} else {
|
|
1251
|
-
this._globalLogLevel = this._logLevelSet.has(
|
|
1269
|
+
this._globalLogLevel = this._logLevelSet.has(levelStr) ? levelStr : this._globalLogLevel;
|
|
1252
1270
|
this._globalLogLevelNumber = this._logLevelValues.indexOf(this._globalLogLevel);
|
|
1253
1271
|
}
|
|
1254
1272
|
}
|
|
@@ -1407,8 +1425,9 @@ var LogM8 = class {
|
|
|
1407
1425
|
}
|
|
1408
1426
|
}
|
|
1409
1427
|
_setLevel(logger, level) {
|
|
1410
|
-
|
|
1411
|
-
logger.
|
|
1428
|
+
const levelStr = (level ?? "").trim().toLowerCase();
|
|
1429
|
+
logger.level = this._logLevelSet.has(levelStr) ? levelStr : logger.level;
|
|
1430
|
+
logger._levelNumber = this._logLevelValues.indexOf(logger.level);
|
|
1412
1431
|
logger.isEnabled = logger.level !== LogLevel.off;
|
|
1413
1432
|
const levelNumber = logger._levelNumber;
|
|
1414
1433
|
logger.isFatal = this._logLevelValues.indexOf(LogLevel.fatal) <= levelNumber;
|
|
@@ -1462,12 +1481,52 @@ var LogM8 = class {
|
|
|
1462
1481
|
}
|
|
1463
1482
|
};
|
|
1464
1483
|
|
|
1484
|
+
// src/NullLogger.ts
|
|
1485
|
+
var NullLogger = class {
|
|
1486
|
+
constructor() {
|
|
1487
|
+
__publicField(this, "isFatal", false);
|
|
1488
|
+
__publicField(this, "isError", false);
|
|
1489
|
+
__publicField(this, "isWarn", false);
|
|
1490
|
+
__publicField(this, "isInfo", false);
|
|
1491
|
+
__publicField(this, "isDebug", false);
|
|
1492
|
+
__publicField(this, "isTrack", false);
|
|
1493
|
+
__publicField(this, "isTrace", false);
|
|
1494
|
+
__publicField(this, "isEnabled", false);
|
|
1495
|
+
__publicField(this, "name", "nullLogger");
|
|
1496
|
+
__publicField(this, "level", "off");
|
|
1497
|
+
__publicField(this, "context", {});
|
|
1498
|
+
}
|
|
1499
|
+
fatal(_message, ..._args) {
|
|
1500
|
+
}
|
|
1501
|
+
error(_message, ..._args) {
|
|
1502
|
+
}
|
|
1503
|
+
warn(_message, ..._args) {
|
|
1504
|
+
}
|
|
1505
|
+
info(_message, ..._args) {
|
|
1506
|
+
}
|
|
1507
|
+
debug(_message, ..._args) {
|
|
1508
|
+
}
|
|
1509
|
+
track(_message, ..._args) {
|
|
1510
|
+
}
|
|
1511
|
+
trace(_message, ..._args) {
|
|
1512
|
+
}
|
|
1513
|
+
setLevel(_level) {
|
|
1514
|
+
}
|
|
1515
|
+
setContext(context) {
|
|
1516
|
+
this.context = context;
|
|
1517
|
+
}
|
|
1518
|
+
getLogger(_name) {
|
|
1519
|
+
return this;
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1465
1523
|
// src/index.ts
|
|
1466
1524
|
var LogM82 = new LogM8();
|
|
1467
1525
|
export {
|
|
1468
1526
|
LogLevel,
|
|
1469
1527
|
LogM82 as LogM8,
|
|
1470
1528
|
LogM8Utils,
|
|
1529
|
+
NullLogger,
|
|
1471
1530
|
PluginKind
|
|
1472
1531
|
};
|
|
1473
1532
|
//# sourceMappingURL=index.js.map
|