@ncoderz/log-m8 1.2.4 → 1.3.0
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/README.md +33 -1
- package/dist/browser/log-m8.global.js +1 -1
- package/dist/browser/log-m8.global.js.map +1 -1
- package/dist/index.cjs +164 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +408 -55
- package/dist/index.d.ts +408 -55
- package/dist/index.js +158 -39
- package/dist/index.js.map +1 -1
- package/package.json +13 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for initializing a plugin.
|
|
3
|
+
*/
|
|
4
|
+
interface PluginConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The plugin's unique name.
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* Additional plugin-specific settings.
|
|
11
|
+
*/
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Defines configuration options for a filter plugin.
|
|
17
|
+
* @extends PluginConfig
|
|
18
|
+
*/
|
|
19
|
+
interface FilterConfig extends PluginConfig {
|
|
20
|
+
/**
|
|
21
|
+
* Whether the filter is enabled.
|
|
22
|
+
*/
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Defines configuration options for a formatter plugin.
|
|
28
|
+
* @extends PluginConfig
|
|
29
|
+
*/
|
|
30
|
+
interface FormatterConfig extends PluginConfig {
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Defines the configuration options for a log appender plugin.
|
|
35
|
+
*/
|
|
36
|
+
interface AppenderConfig extends PluginConfig {
|
|
37
|
+
/**
|
|
38
|
+
* Whether the appender is enabled.
|
|
39
|
+
*/
|
|
40
|
+
enabled?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Priority determining execution order; higher values run first (descending order).
|
|
43
|
+
*/
|
|
44
|
+
priority?: number;
|
|
45
|
+
/**
|
|
46
|
+
* The formatter to apply to log events, specified by name or config object.
|
|
47
|
+
*/
|
|
48
|
+
formatter?: string | FormatterConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Filters to apply to log events, specified by name or config objects.
|
|
51
|
+
*/
|
|
52
|
+
filters?: (string | FilterConfig)[];
|
|
53
|
+
}
|
|
54
|
+
|
|
1
55
|
/**
|
|
2
56
|
* Contextual metadata automatically included with all log events from a logger.
|
|
3
57
|
*
|
|
@@ -268,60 +322,6 @@ interface Log {
|
|
|
268
322
|
getLogger(name: string): Log;
|
|
269
323
|
}
|
|
270
324
|
|
|
271
|
-
/**
|
|
272
|
-
* Configuration options for initializing a plugin.
|
|
273
|
-
*/
|
|
274
|
-
interface PluginConfig {
|
|
275
|
-
/**
|
|
276
|
-
* The plugin's unique name.
|
|
277
|
-
*/
|
|
278
|
-
name: string;
|
|
279
|
-
/**
|
|
280
|
-
* Additional plugin-specific settings.
|
|
281
|
-
*/
|
|
282
|
-
[key: string]: unknown;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Defines configuration options for a filter plugin.
|
|
287
|
-
* @extends PluginConfig
|
|
288
|
-
*/
|
|
289
|
-
interface FilterConfig extends PluginConfig {
|
|
290
|
-
/**
|
|
291
|
-
* Whether the filter is enabled.
|
|
292
|
-
*/
|
|
293
|
-
enabled?: boolean;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Defines configuration options for a formatter plugin.
|
|
298
|
-
* @extends PluginConfig
|
|
299
|
-
*/
|
|
300
|
-
interface FormatterConfig extends PluginConfig {
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Defines the configuration options for a log appender plugin.
|
|
305
|
-
*/
|
|
306
|
-
interface AppenderConfig extends PluginConfig {
|
|
307
|
-
/**
|
|
308
|
-
* Whether the appender is enabled.
|
|
309
|
-
*/
|
|
310
|
-
enabled?: boolean;
|
|
311
|
-
/**
|
|
312
|
-
* Priority determining execution order; higher values run first (descending order).
|
|
313
|
-
*/
|
|
314
|
-
priority?: number;
|
|
315
|
-
/**
|
|
316
|
-
* The formatter to apply to log events, specified by name or config object.
|
|
317
|
-
*/
|
|
318
|
-
formatter?: string | FormatterConfig;
|
|
319
|
-
/**
|
|
320
|
-
* Filters to apply to log events, specified by name or config objects.
|
|
321
|
-
*/
|
|
322
|
-
filters?: (string | FilterConfig)[];
|
|
323
|
-
}
|
|
324
|
-
|
|
325
325
|
/**
|
|
326
326
|
* Primary configuration object for initializing the LogM8 logging system.
|
|
327
327
|
*
|
|
@@ -536,6 +536,7 @@ declare class LogM8$1 {
|
|
|
536
536
|
private _globalLogLevelNumber;
|
|
537
537
|
private _logLevelValues;
|
|
538
538
|
private _logLevelSet;
|
|
539
|
+
private _logLevelIndexMap;
|
|
539
540
|
private _logBuffer;
|
|
540
541
|
constructor();
|
|
541
542
|
/**
|
|
@@ -632,6 +633,75 @@ declare class LogM8$1 {
|
|
|
632
633
|
* @param name - Name of the appender to disable
|
|
633
634
|
*/
|
|
634
635
|
disableAppender(name: string): void;
|
|
636
|
+
/**
|
|
637
|
+
* Adds an appender to the logging system at runtime.
|
|
638
|
+
*
|
|
639
|
+
* Creates and initializes the appender using the plugin factory system,
|
|
640
|
+
* including any configured formatter and filters. The appender is inserted
|
|
641
|
+
* into the priority-sorted appender list and immediately begins receiving
|
|
642
|
+
* log events.
|
|
643
|
+
*
|
|
644
|
+
* Must be called after init(). The appender name must not already be in use.
|
|
645
|
+
*
|
|
646
|
+
* @param config - Appender name (string) or full configuration object
|
|
647
|
+
*
|
|
648
|
+
* @throws {Error} When called before init()
|
|
649
|
+
* @throws {Error} When an appender with the same name already exists
|
|
650
|
+
* @throws {Error} When the referenced plugin factory is not registered
|
|
651
|
+
*
|
|
652
|
+
* @example
|
|
653
|
+
* ```typescript
|
|
654
|
+
* // Add by name (uses factory defaults)
|
|
655
|
+
* Logging.addAppender('console');
|
|
656
|
+
*
|
|
657
|
+
* // Add with full configuration
|
|
658
|
+
* Logging.addAppender({
|
|
659
|
+
* name: 'file',
|
|
660
|
+
* filename: 'debug.log',
|
|
661
|
+
* formatter: 'json-formatter',
|
|
662
|
+
* filters: ['sensitive-data'],
|
|
663
|
+
* priority: 10
|
|
664
|
+
* });
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
addAppender(config: string | AppenderConfig): void;
|
|
668
|
+
/**
|
|
669
|
+
* Removes an appender from the logging system at runtime.
|
|
670
|
+
*
|
|
671
|
+
* Flushes any buffered output, disposes the appender, and removes it
|
|
672
|
+
* from the active appender list. The appender will no longer receive
|
|
673
|
+
* log events after removal.
|
|
674
|
+
*
|
|
675
|
+
* @param name - Name of the appender to remove
|
|
676
|
+
* @returns True if the appender was found and removed, false otherwise
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```typescript
|
|
680
|
+
* // Remove a dynamically added appender
|
|
681
|
+
* Logging.removeAppender('file');
|
|
682
|
+
*
|
|
683
|
+
* // Check if removal succeeded
|
|
684
|
+
* if (!Logging.removeAppender('unknown')) {
|
|
685
|
+
* console.warn('Appender not found');
|
|
686
|
+
* }
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
removeAppender(name: string): boolean;
|
|
690
|
+
/**
|
|
691
|
+
* Returns the names of all currently registered appenders.
|
|
692
|
+
*
|
|
693
|
+
* The returned array is a snapshot; modifications to it do not affect
|
|
694
|
+
* the logging system. Names are in priority-sorted order (highest first).
|
|
695
|
+
*
|
|
696
|
+
* @returns Array of appender names
|
|
697
|
+
*
|
|
698
|
+
* @example
|
|
699
|
+
* ```typescript
|
|
700
|
+
* const names = Logging.getAppenderNames();
|
|
701
|
+
* console.log('Active appenders:', names); // ['console', 'file']
|
|
702
|
+
* ```
|
|
703
|
+
*/
|
|
704
|
+
getAppenderNames(): string[];
|
|
635
705
|
/**
|
|
636
706
|
* Forces an appender to flush any buffered output.
|
|
637
707
|
*
|
|
@@ -712,12 +782,21 @@ declare class LogM8$1 {
|
|
|
712
782
|
private _setLevel;
|
|
713
783
|
private _setContext;
|
|
714
784
|
private _processLogEvent;
|
|
785
|
+
private _createAndInitAppender;
|
|
715
786
|
private _getAppender;
|
|
716
787
|
private _sortAppenders;
|
|
717
788
|
private _getFilter;
|
|
718
789
|
private _reset;
|
|
719
790
|
}
|
|
720
791
|
|
|
792
|
+
declare const PACKAGE_INFO: {
|
|
793
|
+
name: string;
|
|
794
|
+
version: string;
|
|
795
|
+
author: string;
|
|
796
|
+
license: string;
|
|
797
|
+
description: string;
|
|
798
|
+
};
|
|
799
|
+
|
|
721
800
|
/**
|
|
722
801
|
* Structured representation of a single log entry containing all event data.
|
|
723
802
|
*
|
|
@@ -934,6 +1013,56 @@ interface Appender extends Plugin {
|
|
|
934
1013
|
*/
|
|
935
1014
|
interface ConsoleAppenderConfig extends AppenderConfig {
|
|
936
1015
|
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Built-in appender that outputs log events to the global console object.
|
|
1018
|
+
*
|
|
1019
|
+
* Maps log levels to appropriate console methods (error, warn, info, debug, etc.)
|
|
1020
|
+
* with fallback to console.log when specific methods are unavailable.
|
|
1021
|
+
* Automatically detects console availability and gracefully handles environments
|
|
1022
|
+
* where console is not available.
|
|
1023
|
+
*
|
|
1024
|
+
* Features:
|
|
1025
|
+
* - Zero-configuration operation
|
|
1026
|
+
* - Automatic console method mapping by log level
|
|
1027
|
+
* - Graceful degradation when console methods are missing
|
|
1028
|
+
* - No-op flush operation (console output is immediate)
|
|
1029
|
+
* - Environment detection for console availability
|
|
1030
|
+
*
|
|
1031
|
+
* @example
|
|
1032
|
+
* ```typescript
|
|
1033
|
+
* // Automatic registration - no manual setup needed
|
|
1034
|
+
* Logging.init({
|
|
1035
|
+
* appenders: [{ name: 'console', formatter: 'default-formatter' }]
|
|
1036
|
+
* });
|
|
1037
|
+
* ```
|
|
1038
|
+
*/
|
|
1039
|
+
declare class ConsoleAppender implements Appender {
|
|
1040
|
+
name: string;
|
|
1041
|
+
version: string;
|
|
1042
|
+
kind: "appender";
|
|
1043
|
+
readonly supportedLevels: Set<LogLevelType>;
|
|
1044
|
+
enabled: boolean;
|
|
1045
|
+
priority?: number;
|
|
1046
|
+
private _config?;
|
|
1047
|
+
private _formatter?;
|
|
1048
|
+
private _filters;
|
|
1049
|
+
private _available;
|
|
1050
|
+
private off;
|
|
1051
|
+
private fatal;
|
|
1052
|
+
private error;
|
|
1053
|
+
private warn;
|
|
1054
|
+
private info;
|
|
1055
|
+
private debug;
|
|
1056
|
+
private trace;
|
|
1057
|
+
private track;
|
|
1058
|
+
init(config: AppenderConfig, formatter?: Formatter, filters?: Filter[]): void;
|
|
1059
|
+
dispose(): void;
|
|
1060
|
+
write(event: LogEvent): void;
|
|
1061
|
+
flush(): void;
|
|
1062
|
+
enableFilter(name: string): void;
|
|
1063
|
+
disableFilter(name: string): void;
|
|
1064
|
+
private _getFilter;
|
|
1065
|
+
}
|
|
937
1066
|
|
|
938
1067
|
/**
|
|
939
1068
|
* Configuration options for the file appender.
|
|
@@ -947,6 +1076,37 @@ interface FileAppenderConfig extends AppenderConfig {
|
|
|
947
1076
|
/** Append to existing file (true) or overwrite on startup (false). Default: false */
|
|
948
1077
|
append?: boolean;
|
|
949
1078
|
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Appender that writes each formatted log event to a file (one line per event).
|
|
1081
|
+
*
|
|
1082
|
+
* Behavior
|
|
1083
|
+
* - Initializes a WriteStream on init() using the provided filename.
|
|
1084
|
+
* - Joins formatted tokens with a single space and appends a trailing newline.
|
|
1085
|
+
* - If no formatter is configured, writes the raw LogEvent via String() coercion of tokens.
|
|
1086
|
+
* - Respects per-appender filters before writing.
|
|
1087
|
+
* - flush() is a no-op; data is flushed by the stream implementation. dispose() ends the stream.
|
|
1088
|
+
*/
|
|
1089
|
+
declare class FileAppender implements Appender {
|
|
1090
|
+
name: string;
|
|
1091
|
+
version: string;
|
|
1092
|
+
kind: "appender";
|
|
1093
|
+
readonly supportedLevels: Set<LogLevelType>;
|
|
1094
|
+
enabled: boolean;
|
|
1095
|
+
priority?: number;
|
|
1096
|
+
private _config?;
|
|
1097
|
+
private _formatter?;
|
|
1098
|
+
private _filters;
|
|
1099
|
+
private _stream?;
|
|
1100
|
+
private _streamCreationFailed;
|
|
1101
|
+
init(config: AppenderConfig, formatter?: Formatter, filters?: Filter[]): void;
|
|
1102
|
+
dispose(): void;
|
|
1103
|
+
write(event: LogEvent): void;
|
|
1104
|
+
flush(): void;
|
|
1105
|
+
enableFilter(name: string): void;
|
|
1106
|
+
disableFilter(name: string): void;
|
|
1107
|
+
private _getFilter;
|
|
1108
|
+
private _createStream;
|
|
1109
|
+
}
|
|
950
1110
|
|
|
951
1111
|
/**
|
|
952
1112
|
* Configuration for MatchFilter.
|
|
@@ -983,6 +1143,42 @@ interface MatchFilterConfig extends FilterConfig {
|
|
|
983
1143
|
/** If any rule in this map matches, the event will be denied (OR). */
|
|
984
1144
|
deny?: Record<string, unknown>;
|
|
985
1145
|
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Built-in filter providing straightforward allow/deny path-based matching.
|
|
1148
|
+
*
|
|
1149
|
+
* Use this when you want quick, declarative filtering without writing code. Rules are
|
|
1150
|
+
* evaluated against the LogEvent using robust dot-path resolution (with support for
|
|
1151
|
+
* `array[index]` notation). Comparisons use deep equality for objects/arrays and strict
|
|
1152
|
+
* equality for primitives.
|
|
1153
|
+
*/
|
|
1154
|
+
declare class MatchFilter implements Filter {
|
|
1155
|
+
name: string;
|
|
1156
|
+
version: string;
|
|
1157
|
+
kind: "filter";
|
|
1158
|
+
enabled: boolean;
|
|
1159
|
+
private _allow?;
|
|
1160
|
+
private _deny?;
|
|
1161
|
+
/**
|
|
1162
|
+
* Initializes allow/deny rule maps. Values are compared using deep equality for
|
|
1163
|
+
* arrays/objects and strict equality for primitives. Missing maps are treated as empty.
|
|
1164
|
+
* @param config - Filter configuration with optional allow/deny maps
|
|
1165
|
+
*/
|
|
1166
|
+
init(config: FilterConfig): void;
|
|
1167
|
+
dispose(): void;
|
|
1168
|
+
/**
|
|
1169
|
+
* Evaluates the given event against configured rules.
|
|
1170
|
+
* - allow: if provided and non-empty, ALL rules must match (AND)
|
|
1171
|
+
* - deny: if provided, ANY match denies (OR); deny takes precedence over allow
|
|
1172
|
+
* Returns false on unexpected errors to fail-safe.
|
|
1173
|
+
* @param logEvent - Event to evaluate
|
|
1174
|
+
* @returns true when the event should be logged; false to drop
|
|
1175
|
+
*/
|
|
1176
|
+
filter(logEvent: LogEvent): boolean;
|
|
1177
|
+
private _matches;
|
|
1178
|
+
private _isEqual;
|
|
1179
|
+
private _isPlainObject;
|
|
1180
|
+
private _prepareRules;
|
|
1181
|
+
}
|
|
986
1182
|
|
|
987
1183
|
/**
|
|
988
1184
|
* Configuration for the default text formatter.
|
|
@@ -1013,6 +1209,163 @@ interface DefaultFormatterConfig extends FormatterConfig {
|
|
|
1013
1209
|
*/
|
|
1014
1210
|
color?: boolean;
|
|
1015
1211
|
}
|
|
1212
|
+
/**
|
|
1213
|
+
* Built-in text formatter with token-based templates and optional colorized levels.
|
|
1214
|
+
*
|
|
1215
|
+
* Features
|
|
1216
|
+
* - Customizable templates using curly-brace tokens mixed with literal text.
|
|
1217
|
+
* - Timestamp formatting via presets or custom patterns.
|
|
1218
|
+
* - Optional colorization of the {LEVEL} token (ANSI in Node.js, CSS tuple in browsers).
|
|
1219
|
+
*
|
|
1220
|
+
* Notes
|
|
1221
|
+
* - This formatter outputs text (not JSON). It returns an array of strings/values that
|
|
1222
|
+
* appenders can pass to console/file outputs.
|
|
1223
|
+
* - The {data} token resolves to the `logEvent.data` array. If present as its own
|
|
1224
|
+
* line entry, items are expanded in-place; if the array is empty, the token is removed.
|
|
1225
|
+
* - {message} is passed through as-is when it’s not a string (e.g., objects or errors).
|
|
1226
|
+
* - Any other token (including nested paths like {context.userId}) is resolved using
|
|
1227
|
+
* dot-path access on the LogEvent.
|
|
1228
|
+
*
|
|
1229
|
+
* Supported tokens
|
|
1230
|
+
* - {timestamp}: Formatted with `timestampFormat`.
|
|
1231
|
+
* - {LEVEL}: Uppercase level label (with optional colorization/padding).
|
|
1232
|
+
* - {level}: Lowercase level name.
|
|
1233
|
+
* - {logger}: Logger name.
|
|
1234
|
+
* - {message}: Primary log message (string or non-string value).
|
|
1235
|
+
* - {data}: Additional data arguments array (expanded inline when present alone in a line).
|
|
1236
|
+
* - {context.*}: Nested context properties.
|
|
1237
|
+
*
|
|
1238
|
+
* @example
|
|
1239
|
+
* // Text with colors
|
|
1240
|
+
* formatter.init({
|
|
1241
|
+
* format: '{timestamp} {LEVEL} [{logger}] {message}',
|
|
1242
|
+
* timestampFormat: 'hh:mm:ss.SSS',
|
|
1243
|
+
* color: true,
|
|
1244
|
+
* });
|
|
1245
|
+
*
|
|
1246
|
+
* // Multi-line text output with expanded data
|
|
1247
|
+
* formatter.init({
|
|
1248
|
+
* format: [
|
|
1249
|
+
* '{timestamp} {LEVEL} [{logger}] {message}',
|
|
1250
|
+
* 'Context: {context}',
|
|
1251
|
+
* 'Data: {data}',
|
|
1252
|
+
* ],
|
|
1253
|
+
* });
|
|
1254
|
+
*/
|
|
1255
|
+
declare class DefaultFormatter implements Formatter {
|
|
1256
|
+
name: string;
|
|
1257
|
+
version: string;
|
|
1258
|
+
kind: "formatter";
|
|
1259
|
+
private _config;
|
|
1260
|
+
private _format;
|
|
1261
|
+
private _timestampFormat;
|
|
1262
|
+
private _levelMap;
|
|
1263
|
+
private _colorEnabled;
|
|
1264
|
+
private _levelColorMap;
|
|
1265
|
+
private _levelCssColorMap;
|
|
1266
|
+
init(config: DefaultFormatterConfig): void;
|
|
1267
|
+
dispose(): void;
|
|
1268
|
+
format(logEvent: LogEvent): unknown[];
|
|
1269
|
+
private resolveToken;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
/**
|
|
1273
|
+
* Configuration for the JSON formatter.
|
|
1274
|
+
*
|
|
1275
|
+
* Extends the base FormatterConfig with options for selecting which fields to
|
|
1276
|
+
* include, pretty printing, timestamp formatting, and output size limits.
|
|
1277
|
+
*/
|
|
1278
|
+
interface JsonFormatterConfig extends FormatterConfig {
|
|
1279
|
+
/**
|
|
1280
|
+
* Fields to include in the output object.
|
|
1281
|
+
* Accepts a single field or an array of fields. Defaults to
|
|
1282
|
+
* ['timestamp', 'level', 'logger', 'message', 'data'].
|
|
1283
|
+
*
|
|
1284
|
+
* Each entry is used as the object key and resolved via dot-path on the LogEvent.
|
|
1285
|
+
* Special handling:
|
|
1286
|
+
* - 'LEVEL' returns the raw level string (e.g., 'info').
|
|
1287
|
+
* - 'timestamp' is formatted with `timestampFormat`.
|
|
1288
|
+
*
|
|
1289
|
+
* If the list is empty, the entire LogEvent object is used.
|
|
1290
|
+
*/
|
|
1291
|
+
format?: string | string[];
|
|
1292
|
+
/**
|
|
1293
|
+
* Pretty-print JSON output.
|
|
1294
|
+
* - true: default indentation of 2 spaces.
|
|
1295
|
+
* - number: use the provided number of spaces.
|
|
1296
|
+
* - false/undefined: minified JSON with no extra whitespace.
|
|
1297
|
+
*/
|
|
1298
|
+
pretty?: boolean | number;
|
|
1299
|
+
/**
|
|
1300
|
+
* Timestamp format pattern or preset.
|
|
1301
|
+
* Supports 'iso', 'locale', or custom token patterns (yyyy-MM-dd hh:mm:ss).
|
|
1302
|
+
*/
|
|
1303
|
+
timestampFormat?: string;
|
|
1304
|
+
/**
|
|
1305
|
+
* Maximum depth for nested objects in JSON output.
|
|
1306
|
+
* Defaults to 3.
|
|
1307
|
+
*/
|
|
1308
|
+
maxDepth?: number;
|
|
1309
|
+
/**
|
|
1310
|
+
* Maximum length for string values in JSON output.
|
|
1311
|
+
* Strings longer than this may be truncated by `stringifyLog`. Defaults to 1000.
|
|
1312
|
+
*/
|
|
1313
|
+
maxStringLen?: number;
|
|
1314
|
+
/**
|
|
1315
|
+
* Maximum length for array values in JSON output.
|
|
1316
|
+
* Arrays longer than this may be truncated by `stringifyLog`. Defaults to 100.
|
|
1317
|
+
*/
|
|
1318
|
+
maxArrayLen?: number;
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* JSON formatter that emits a single JSON string per log event.
|
|
1322
|
+
*
|
|
1323
|
+
* Features
|
|
1324
|
+
* - Select fields via `format` (e.g., ['timestamp','level','logger','message','data']).
|
|
1325
|
+
* - Formats timestamps using `timestampFormat` ('iso', 'locale', or custom pattern).
|
|
1326
|
+
* - Pretty printing with fixed (2 spaces) or custom indentation.
|
|
1327
|
+
* - Output size controls via `maxDepth`, `maxStringLen`, and `maxArrayLen` (passed to `LogM8Utils.stringifyLog`).
|
|
1328
|
+
*
|
|
1329
|
+
* Behavior
|
|
1330
|
+
* - Returns an array with a single element: the JSON string representation of the selected fields.
|
|
1331
|
+
* - Field resolution uses dot-path access on the LogEvent (e.g., 'context.userId').
|
|
1332
|
+
* - Special tokens:
|
|
1333
|
+
* - 'timestamp': formatted per `timestampFormat`.
|
|
1334
|
+
* - 'LEVEL': raw level string (lowercase; no color or padding).
|
|
1335
|
+
* - If `format` is empty, the entire LogEvent object is serialized.
|
|
1336
|
+
*
|
|
1337
|
+
* Examples
|
|
1338
|
+
*
|
|
1339
|
+
* // Default fields, minified JSON
|
|
1340
|
+
* formatter.init({});
|
|
1341
|
+
* // => ["{\"timestamp\":\"...\",\"level\":\"info\",\"logger\":\"app\",\"message\":\"...\",\"data\":[]}"]
|
|
1342
|
+
*
|
|
1343
|
+
* // Pretty printed output (2 spaces)
|
|
1344
|
+
* formatter.init({ pretty: true });
|
|
1345
|
+
*
|
|
1346
|
+
* // Custom fields with a nested context property
|
|
1347
|
+
* formatter.init({
|
|
1348
|
+
* format: ['timestamp', 'LEVEL', 'logger', 'context.userId', 'message'],
|
|
1349
|
+
* timestampFormat: 'hh:mm:ss.SSS',
|
|
1350
|
+
* pretty: 2,
|
|
1351
|
+
* });
|
|
1352
|
+
*/
|
|
1353
|
+
declare class JsonFormatter implements Formatter {
|
|
1354
|
+
name: string;
|
|
1355
|
+
version: string;
|
|
1356
|
+
kind: "formatter";
|
|
1357
|
+
private _config;
|
|
1358
|
+
private _format;
|
|
1359
|
+
private _pretty;
|
|
1360
|
+
private _maxDepth;
|
|
1361
|
+
private _maxStringLen;
|
|
1362
|
+
private _maxArrayLen;
|
|
1363
|
+
private _timestampFormat;
|
|
1364
|
+
init(config: JsonFormatterConfig): void;
|
|
1365
|
+
dispose(): void;
|
|
1366
|
+
format(logEvent: LogEvent): unknown[];
|
|
1367
|
+
private resolveToken;
|
|
1368
|
+
}
|
|
1016
1369
|
|
|
1017
1370
|
interface StringifyLogOptions {
|
|
1018
1371
|
/** Max object/array nesting depth to descend into (default 3). */
|
|
@@ -1324,4 +1677,4 @@ declare class NullLogger implements Log {
|
|
|
1324
1677
|
*/
|
|
1325
1678
|
declare const LogM8: LogM8$1;
|
|
1326
1679
|
|
|
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 };
|
|
1680
|
+
export { type Appender, type AppenderConfig, ConsoleAppender, type ConsoleAppenderConfig, DefaultFormatter, type DefaultFormatterConfig, FileAppender, type FileAppenderConfig, type Filter, type FilterConfig, type Formatter, type FormatterConfig, JsonFormatter, type JsonFormatterConfig, type Log, type LogContext, type LogEvent, LogLevel, type LogLevelType, LogM8, LogM8Utils, type LoggingConfig, MatchFilter, type MatchFilterConfig, NullLogger, PACKAGE_INFO, type Plugin, type PluginConfig, type PluginFactory, PluginKind, type PluginKindType };
|