@matter/general 0.13.0-alpha.0-20250318-c1aa38b08 → 0.13.0-alpha.0-20250323-770919c6a
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/cjs/codec/DnsCodec.js +1 -1
- package/dist/cjs/codec/DnsCodec.js.map +1 -1
- package/dist/cjs/log/Console.d.ts +21 -0
- package/dist/cjs/log/Console.d.ts.map +1 -0
- package/dist/cjs/log/Console.js +58 -0
- package/dist/cjs/log/Console.js.map +6 -0
- package/dist/cjs/log/Diagnostic.d.ts +6 -0
- package/dist/cjs/log/Diagnostic.d.ts.map +1 -1
- package/dist/cjs/log/Diagnostic.js +16 -0
- package/dist/cjs/log/Diagnostic.js.map +1 -1
- package/dist/cjs/log/LogDestination.d.ts +67 -0
- package/dist/cjs/log/LogDestination.d.ts.map +1 -0
- package/dist/cjs/log/LogDestination.js +65 -0
- package/dist/cjs/log/LogDestination.js.map +6 -0
- package/dist/cjs/log/LogFormat.d.ts +18 -12
- package/dist/cjs/log/LogFormat.d.ts.map +1 -1
- package/dist/cjs/log/LogFormat.js +17 -24
- package/dist/cjs/log/LogFormat.js.map +1 -1
- package/dist/cjs/log/LogLevel.d.ts +19 -9
- package/dist/cjs/log/LogLevel.d.ts.map +1 -1
- package/dist/cjs/log/LogLevel.js +40 -25
- package/dist/cjs/log/LogLevel.js.map +1 -1
- package/dist/cjs/log/Logger.d.ts +165 -109
- package/dist/cjs/log/Logger.d.ts.map +1 -1
- package/dist/cjs/log/Logger.js +307 -254
- package/dist/cjs/log/Logger.js.map +2 -2
- package/dist/cjs/log/index.d.ts +1 -0
- package/dist/cjs/log/index.d.ts.map +1 -1
- package/dist/cjs/log/index.js +1 -0
- package/dist/cjs/log/index.js.map +1 -1
- package/dist/cjs/time/Time.d.ts +1 -0
- package/dist/cjs/time/Time.d.ts.map +1 -1
- package/dist/cjs/time/Time.js +3 -0
- package/dist/cjs/time/Time.js.map +1 -1
- package/dist/cjs/transaction/Participant.d.ts +3 -3
- package/dist/cjs/transaction/Participant.d.ts.map +1 -1
- package/dist/cjs/transaction/Transaction.d.ts +20 -20
- package/dist/cjs/transaction/Tx.js +3 -3
- package/dist/cjs/transaction/Tx.js.map +1 -1
- package/dist/cjs/util/Construction.js +2 -2
- package/dist/cjs/util/Construction.js.map +1 -1
- package/dist/cjs/util/DataReadQueue.d.ts +4 -0
- package/dist/cjs/util/DataReadQueue.d.ts.map +1 -1
- package/dist/cjs/util/DataReadQueue.js +6 -0
- package/dist/cjs/util/DataReadQueue.js.map +1 -1
- package/dist/cjs/util/FormattedText.js +4 -2
- package/dist/cjs/util/FormattedText.js.map +1 -1
- package/dist/cjs/util/Observable.d.ts +137 -12
- package/dist/cjs/util/Observable.d.ts.map +1 -1
- package/dist/cjs/util/Observable.js +297 -35
- package/dist/cjs/util/Observable.js.map +2 -2
- package/dist/esm/codec/DnsCodec.js +1 -1
- package/dist/esm/codec/DnsCodec.js.map +1 -1
- package/dist/esm/log/Console.d.ts +21 -0
- package/dist/esm/log/Console.d.ts.map +1 -0
- package/dist/esm/log/Console.js +38 -0
- package/dist/esm/log/Console.js.map +6 -0
- package/dist/esm/log/Diagnostic.d.ts +6 -0
- package/dist/esm/log/Diagnostic.d.ts.map +1 -1
- package/dist/esm/log/Diagnostic.js +16 -0
- package/dist/esm/log/Diagnostic.js.map +1 -1
- package/dist/esm/log/LogDestination.d.ts +67 -0
- package/dist/esm/log/LogDestination.d.ts.map +1 -0
- package/dist/esm/log/LogDestination.js +45 -0
- package/dist/esm/log/LogDestination.js.map +6 -0
- package/dist/esm/log/LogFormat.d.ts +18 -12
- package/dist/esm/log/LogFormat.d.ts.map +1 -1
- package/dist/esm/log/LogFormat.js +17 -24
- package/dist/esm/log/LogFormat.js.map +1 -1
- package/dist/esm/log/LogLevel.d.ts +19 -9
- package/dist/esm/log/LogLevel.d.ts.map +1 -1
- package/dist/esm/log/LogLevel.js +40 -25
- package/dist/esm/log/LogLevel.js.map +1 -1
- package/dist/esm/log/Logger.d.ts +165 -109
- package/dist/esm/log/Logger.d.ts.map +1 -1
- package/dist/esm/log/Logger.js +307 -254
- package/dist/esm/log/Logger.js.map +2 -2
- package/dist/esm/log/index.d.ts +1 -0
- package/dist/esm/log/index.d.ts.map +1 -1
- package/dist/esm/log/index.js +1 -0
- package/dist/esm/log/index.js.map +1 -1
- package/dist/esm/time/Time.d.ts +1 -0
- package/dist/esm/time/Time.d.ts.map +1 -1
- package/dist/esm/time/Time.js +3 -0
- package/dist/esm/time/Time.js.map +1 -1
- package/dist/esm/transaction/Participant.d.ts +3 -3
- package/dist/esm/transaction/Participant.d.ts.map +1 -1
- package/dist/esm/transaction/Transaction.d.ts +20 -20
- package/dist/esm/transaction/Tx.js +3 -3
- package/dist/esm/transaction/Tx.js.map +1 -1
- package/dist/esm/util/Construction.js +2 -2
- package/dist/esm/util/Construction.js.map +1 -1
- package/dist/esm/util/DataReadQueue.d.ts +4 -0
- package/dist/esm/util/DataReadQueue.d.ts.map +1 -1
- package/dist/esm/util/DataReadQueue.js +6 -0
- package/dist/esm/util/DataReadQueue.js.map +1 -1
- package/dist/esm/util/FormattedText.js +4 -2
- package/dist/esm/util/FormattedText.js.map +1 -1
- package/dist/esm/util/Observable.d.ts +137 -12
- package/dist/esm/util/Observable.d.ts.map +1 -1
- package/dist/esm/util/Observable.js +297 -35
- package/dist/esm/util/Observable.js.map +2 -2
- package/package.json +2 -2
- package/src/codec/DnsCodec.ts +1 -1
- package/src/log/Console.ts +52 -0
- package/src/log/Diagnostic.ts +21 -0
- package/src/log/LogDestination.ts +113 -0
- package/src/log/LogFormat.ts +39 -36
- package/src/log/LogLevel.ts +55 -25
- package/src/log/Logger.ts +394 -314
- package/src/log/index.ts +1 -0
- package/src/time/Time.ts +4 -0
- package/src/transaction/Participant.ts +3 -3
- package/src/transaction/Transaction.ts +1 -1
- package/src/transaction/Tx.ts +3 -3
- package/src/util/Construction.ts +2 -2
- package/src/util/DataReadQueue.ts +7 -0
- package/src/util/FormattedText.ts +4 -2
- package/src/util/Observable.ts +453 -47
package/dist/cjs/log/Logger.js
CHANGED
|
@@ -18,8 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var Logger_exports = {};
|
|
20
20
|
__export(Logger_exports, {
|
|
21
|
-
Logger: () => Logger
|
|
22
|
-
consoleLogger: () => consoleLogger
|
|
21
|
+
Logger: () => Logger
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(Logger_exports);
|
|
25
24
|
var import_Boot = require("#util/Boot.js");
|
|
@@ -28,6 +27,7 @@ var import_MatterError = require("../MatterError.js");
|
|
|
28
27
|
var import_Time = require("../time/Time.js");
|
|
29
28
|
var import_Bytes = require("../util/Bytes.js");
|
|
30
29
|
var import_Diagnostic = require("./Diagnostic.js");
|
|
30
|
+
var import_LogDestination = require("./LogDestination.js");
|
|
31
31
|
var import_LogFormat = require("./LogFormat.js");
|
|
32
32
|
var import_LogLevel = require("./LogLevel.js");
|
|
33
33
|
/**
|
|
@@ -35,363 +35,387 @@ var import_LogLevel = require("./LogLevel.js");
|
|
|
35
35
|
* Copyright 2022-2025 Matter.js Authors
|
|
36
36
|
* SPDX-License-Identifier: Apache-2.0
|
|
37
37
|
*/
|
|
38
|
-
function consoleLogger(level, formattedLog) {
|
|
39
|
-
const console2 = consoleLogger.console;
|
|
40
|
-
switch (level) {
|
|
41
|
-
case import_LogLevel.LogLevel.DEBUG:
|
|
42
|
-
console2.debug(formattedLog);
|
|
43
|
-
break;
|
|
44
|
-
case import_LogLevel.LogLevel.INFO:
|
|
45
|
-
console2.info(formattedLog);
|
|
46
|
-
break;
|
|
47
|
-
case import_LogLevel.LogLevel.NOTICE:
|
|
48
|
-
console2.info(formattedLog);
|
|
49
|
-
break;
|
|
50
|
-
case import_LogLevel.LogLevel.WARN:
|
|
51
|
-
console2.warn(formattedLog);
|
|
52
|
-
break;
|
|
53
|
-
case import_LogLevel.LogLevel.ERROR:
|
|
54
|
-
console2.error(formattedLog);
|
|
55
|
-
break;
|
|
56
|
-
case import_LogLevel.LogLevel.FATAL:
|
|
57
|
-
console2.error(formattedLog);
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const globalConsole = console;
|
|
62
|
-
((consoleLogger2) => {
|
|
63
|
-
consoleLogger2.console = globalConsole;
|
|
64
|
-
})(consoleLogger || (consoleLogger = {}));
|
|
65
|
-
function logFormatterFor(formatName) {
|
|
66
|
-
const format = (0, import_LogFormat.LogFormat)(formatName);
|
|
67
|
-
return (now, level, facility, prefix, ...values) => format(import_Diagnostic.Diagnostic.message({ now, level, facility, prefix, values }));
|
|
68
|
-
}
|
|
69
38
|
class Logger {
|
|
70
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Log destinations.
|
|
41
|
+
*
|
|
42
|
+
* By default there is a single destination named "default". You can create new destinations using
|
|
43
|
+
* {@link LogDestination}. Add or remove destinations by modifying this object.
|
|
44
|
+
*
|
|
45
|
+
* Throws an error if you access a destination that doesn't exist.
|
|
46
|
+
*/
|
|
47
|
+
static destinations = (0, import_LogDestination.LogDestinations)();
|
|
48
|
+
/**
|
|
49
|
+
* The number of indents to print with messages.
|
|
50
|
+
*/
|
|
71
51
|
static nestingLevel;
|
|
72
52
|
#name;
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Create a new logger for a facility.
|
|
55
|
+
*
|
|
56
|
+
* @param name the name of the facility
|
|
57
|
+
* @returns a new facility
|
|
58
|
+
*/
|
|
59
|
+
static get(name) {
|
|
60
|
+
return new Logger(name);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get the default log level.
|
|
64
|
+
*/
|
|
65
|
+
static get level() {
|
|
66
|
+
return import_LogDestination.LogDestination.defaults.level;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Set log level as name or number for all destinations.
|
|
70
|
+
*/
|
|
71
|
+
static set level(level) {
|
|
72
|
+
level = (0, import_LogLevel.LogLevel)(level);
|
|
73
|
+
import_LogDestination.LogDestination.defaults.level = level;
|
|
74
|
+
for (const name in this.destinations) {
|
|
75
|
+
this.destinations[name].level = level;
|
|
77
76
|
}
|
|
78
|
-
Logger.logger.push({
|
|
79
|
-
logIdentifier: identifier,
|
|
80
|
-
logFormatter: logFormatterFor(options?.logFormat ?? import_LogFormat.LogFormat.PLAIN),
|
|
81
|
-
log: logger,
|
|
82
|
-
defaultLogLevel: options?.defaultLogLevel ?? import_LogLevel.LogLevel.DEBUG,
|
|
83
|
-
logLevels: options?.logLevels ?? {}
|
|
84
|
-
});
|
|
85
77
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Get the default facility levels.
|
|
80
|
+
*/
|
|
81
|
+
static get facilityLevels() {
|
|
82
|
+
return import_LogDestination.LogDestination.defaults.facilityLevels;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Set log level as name or number for facilities in all destinations.
|
|
86
|
+
*
|
|
87
|
+
* Existing levels that are not named in {@link levels} will remain unchanged.
|
|
88
|
+
*/
|
|
89
|
+
static set facilityLevels(levels) {
|
|
90
|
+
for (const name in levels) {
|
|
91
|
+
levels[name] = (0, import_LogLevel.LogLevel)(levels[name]);
|
|
92
|
+
}
|
|
93
|
+
Object.assign(import_LogDestination.LogDestination.defaults.facilityLevels, levels);
|
|
94
|
+
for (const name in this.destinations) {
|
|
95
|
+
Object.assign(this.destinations[name].facilityLevels, levels);
|
|
90
96
|
}
|
|
91
|
-
Logger.logger.splice(index, 1);
|
|
92
97
|
}
|
|
93
98
|
/**
|
|
94
|
-
* Get the
|
|
95
|
-
* @param identifier The identifier of the logger
|
|
99
|
+
* Get the default format name.
|
|
96
100
|
*/
|
|
97
|
-
static
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
static get format() {
|
|
102
|
+
return import_LogDestination.LogDestination.defaults.format.name;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Set the format for all destinations.
|
|
106
|
+
*/
|
|
107
|
+
static set format(format) {
|
|
108
|
+
format = (0, import_LogFormat.LogFormat)(format);
|
|
109
|
+
import_LogDestination.LogDestination.defaults.format = format;
|
|
110
|
+
for (const name in this.destinations) {
|
|
111
|
+
this.destinations[name].format = format;
|
|
101
112
|
}
|
|
102
|
-
return logger;
|
|
103
113
|
}
|
|
104
114
|
/**
|
|
105
|
-
*
|
|
115
|
+
* Mask a string with a given character. If unmaskedLength is provided then these number of characters will be
|
|
116
|
+
* shown unmasked.
|
|
117
|
+
*
|
|
118
|
+
* @param str String to mask
|
|
119
|
+
* @param maskChar character to mask with
|
|
120
|
+
* @param unmaskedLength number of characters to show unmasked in the beginning
|
|
106
121
|
*/
|
|
107
|
-
static
|
|
108
|
-
|
|
109
|
-
|
|
122
|
+
static maskString(str, maskChar = "*", unmaskedLength) {
|
|
123
|
+
return str.substring(0, unmaskedLength ?? 0) + str.substring(unmaskedLength ?? 0).replace(/./g, maskChar);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Perform operations in a nested logging context. Messages will be
|
|
127
|
+
* indented while the context executes.
|
|
128
|
+
*/
|
|
129
|
+
static nest(context) {
|
|
130
|
+
this.nestingLevel++;
|
|
131
|
+
try {
|
|
132
|
+
return context();
|
|
133
|
+
} finally {
|
|
134
|
+
this.nestingLevel--;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Async version of nest().
|
|
139
|
+
*/
|
|
140
|
+
static async nestAsync(context) {
|
|
141
|
+
this.nestingLevel++;
|
|
142
|
+
try {
|
|
143
|
+
return await context();
|
|
144
|
+
} finally {
|
|
145
|
+
this.nestingLevel--;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Unhandled error reporter.
|
|
150
|
+
*
|
|
151
|
+
* Some environments do not report full error details such as {@link Error#cause} and {@link AggregateError#errors}.
|
|
152
|
+
*
|
|
153
|
+
* To ensure these details are always recorded somewhere, unhandled errors may be reported here.
|
|
154
|
+
*
|
|
155
|
+
* To disable this behavior replace this function.
|
|
156
|
+
*/
|
|
157
|
+
static reportUnhandledError(error) {
|
|
158
|
+
try {
|
|
159
|
+
Logger.get("Logger").fatal("Unhandled error detected:", error);
|
|
160
|
+
} catch (e) {
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
constructor(name) {
|
|
164
|
+
this.#name = name;
|
|
165
|
+
}
|
|
166
|
+
debug(...values) {
|
|
167
|
+
this.#log(import_LogLevel.LogLevel.DEBUG, values);
|
|
168
|
+
}
|
|
169
|
+
info(...values) {
|
|
170
|
+
this.#log(import_LogLevel.LogLevel.INFO, values);
|
|
171
|
+
}
|
|
172
|
+
notice(...values) {
|
|
173
|
+
this.#log(import_LogLevel.LogLevel.NOTICE, values);
|
|
174
|
+
}
|
|
175
|
+
warn(...values) {
|
|
176
|
+
this.#log(import_LogLevel.LogLevel.WARN, values);
|
|
177
|
+
}
|
|
178
|
+
error(...values) {
|
|
179
|
+
this.#log(import_LogLevel.LogLevel.ERROR, values);
|
|
180
|
+
}
|
|
181
|
+
fatal(...values) {
|
|
182
|
+
this.#log(import_LogLevel.LogLevel.FATAL, values);
|
|
183
|
+
}
|
|
184
|
+
log(level, ...values) {
|
|
185
|
+
this.#log(level, values);
|
|
186
|
+
}
|
|
187
|
+
#log(level, values) {
|
|
188
|
+
for (const name in Logger.destinations) {
|
|
189
|
+
const dest = Logger.destinations[name];
|
|
190
|
+
if (level < (dest.facilityLevels?.[this.#name] ?? dest.level)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (!dest.context) {
|
|
194
|
+
dest.context = import_Diagnostic.Diagnostic.Context();
|
|
195
|
+
}
|
|
196
|
+
dest.context.run(
|
|
197
|
+
() => dest.add(
|
|
198
|
+
import_Diagnostic.Diagnostic.message({
|
|
199
|
+
now: import_Time.Time.now(),
|
|
200
|
+
facility: this.#name,
|
|
201
|
+
level,
|
|
202
|
+
prefix: nestingPrefix(),
|
|
203
|
+
values
|
|
204
|
+
})
|
|
205
|
+
)
|
|
206
|
+
);
|
|
110
207
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
208
|
+
}
|
|
209
|
+
//
|
|
210
|
+
// DEPRECATED API SURFACE FOLLOWS
|
|
211
|
+
//
|
|
212
|
+
/**
|
|
213
|
+
* Stringify a value (BigInt aware) as JSON.
|
|
214
|
+
*
|
|
215
|
+
* @param data the value to stringify
|
|
216
|
+
* @returns the stringified value
|
|
217
|
+
*
|
|
218
|
+
* @deprecated use {@link Diagnostic.json}
|
|
219
|
+
*/
|
|
220
|
+
static toJSON(data) {
|
|
221
|
+
return JSON.stringify(data, (_, value) => {
|
|
222
|
+
if (typeof value === "bigint") {
|
|
223
|
+
return value.toString();
|
|
224
|
+
}
|
|
225
|
+
if (value instanceof Uint8Array) {
|
|
226
|
+
return import_Bytes.Bytes.toHex(value);
|
|
120
227
|
}
|
|
121
|
-
|
|
122
|
-
|
|
228
|
+
if (value === void 0) {
|
|
229
|
+
return "undefined";
|
|
230
|
+
}
|
|
231
|
+
return value;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Add additional logger to the list of loggers including the default configuration.
|
|
236
|
+
*
|
|
237
|
+
* @deprecated use {@link destinations}
|
|
238
|
+
*/
|
|
239
|
+
static addLogger(identifier, logger, options) {
|
|
240
|
+
if (identifier in this.destinations) {
|
|
241
|
+
throw new import_MatterError.ImplementationError(`Logger "${identifier}" already exists`);
|
|
242
|
+
}
|
|
243
|
+
const dest = (0, import_LogDestination.LogDestination)({ name: identifier });
|
|
244
|
+
const legacy = adaptDestinationToLegacy(dest);
|
|
245
|
+
legacy.log = logger;
|
|
246
|
+
if (options?.defaultLogLevel !== void 0) {
|
|
247
|
+
legacy.defaultLogLevel = options.defaultLogLevel;
|
|
248
|
+
}
|
|
249
|
+
if (options?.logLevels !== void 0) {
|
|
250
|
+
legacy.logLevels = options.logLevels;
|
|
251
|
+
}
|
|
252
|
+
if (options?.logFormat !== void 0) {
|
|
253
|
+
legacy.logFormatter = logFormatterFor(options.logFormat);
|
|
123
254
|
}
|
|
124
|
-
|
|
125
|
-
|
|
255
|
+
this.destinations[identifier] = dest;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @deprecated use {@link destinations}
|
|
259
|
+
*/
|
|
260
|
+
static removeLogger(identifier) {
|
|
261
|
+
if (!(identifier in this.destinations)) {
|
|
262
|
+
throw new import_MatterError.NotImplementedError(`Logger "${identifier}" does not exist`);
|
|
126
263
|
}
|
|
127
|
-
|
|
264
|
+
delete this.destinations[identifier];
|
|
128
265
|
}
|
|
129
266
|
/**
|
|
130
|
-
*
|
|
267
|
+
* Check if a logger with the matching identifier exists.
|
|
268
|
+
* @param identifier The identifier of the logger
|
|
131
269
|
*
|
|
132
|
-
* @
|
|
270
|
+
* @deprecated use {@link destinations}
|
|
133
271
|
*/
|
|
134
|
-
static
|
|
135
|
-
|
|
272
|
+
static hasLoggerForIdentifier(identifier) {
|
|
273
|
+
return identifier in this.destinations;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Get the logger with the matching identifier.
|
|
277
|
+
* @param identifier The identifier of the logger
|
|
278
|
+
*
|
|
279
|
+
* @deprecated use {@link destinations}
|
|
280
|
+
*/
|
|
281
|
+
static getLoggerForIdentifier(identifier) {
|
|
282
|
+
const dest = this.destinations[identifier];
|
|
283
|
+
if (dest === void 0) {
|
|
284
|
+
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
285
|
+
}
|
|
286
|
+
return adaptDestinationToLegacy(dest);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* @deprecated use {@link destinations}
|
|
290
|
+
*/
|
|
291
|
+
static getLoggerforIdentifier(identifier) {
|
|
292
|
+
return this.getLoggerForIdentifier(identifier);
|
|
136
293
|
}
|
|
137
294
|
/**
|
|
138
295
|
* Set facility loglevels for the default logger.
|
|
139
296
|
* @param levels The levels to set
|
|
297
|
+
*
|
|
298
|
+
* @deprecated use {@link destinations}
|
|
140
299
|
*/
|
|
141
300
|
static set logLevels(levels) {
|
|
142
301
|
Logger.setLogLevelsForLogger("default", levels);
|
|
143
302
|
}
|
|
144
303
|
/**
|
|
145
304
|
* Get facility loglevels for the default logger.
|
|
305
|
+
*
|
|
306
|
+
* @deprecated use {@link Logger.facilityLevels}
|
|
146
307
|
*/
|
|
147
308
|
static get logLevels() {
|
|
148
|
-
return Logger.
|
|
309
|
+
return Logger.getLoggerForIdentifier("default").logLevels;
|
|
149
310
|
}
|
|
150
311
|
/**
|
|
151
312
|
* Set default loglevel for the default logger.
|
|
152
313
|
*
|
|
153
314
|
* @param level The level to set
|
|
315
|
+
*
|
|
316
|
+
* @deprecated use {@link Logger.level}
|
|
154
317
|
*/
|
|
155
318
|
static set defaultLogLevel(level) {
|
|
156
319
|
Logger.setDefaultLoglevelForLogger("default", level);
|
|
157
320
|
}
|
|
158
321
|
/**
|
|
159
322
|
* Get default loglevel for the default logger.
|
|
323
|
+
*
|
|
324
|
+
* @deprecated use {@link destinations}
|
|
160
325
|
*/
|
|
161
326
|
static get defaultLogLevel() {
|
|
162
|
-
return Logger.
|
|
327
|
+
return Logger.getLoggerForIdentifier("default").defaultLogLevel;
|
|
163
328
|
}
|
|
164
329
|
/**
|
|
165
330
|
* Set the log function for the default logger.
|
|
166
331
|
*
|
|
167
332
|
* @param log The log function to set
|
|
333
|
+
*
|
|
334
|
+
* @deprecated use {@link destinations}
|
|
168
335
|
*/
|
|
169
336
|
static set log(log) {
|
|
170
337
|
Logger.setLogger("default", log);
|
|
171
338
|
}
|
|
172
339
|
/**
|
|
173
340
|
* Get the log function for the default logger.
|
|
341
|
+
*
|
|
342
|
+
* @deprecated use {@link destinations}
|
|
174
343
|
*/
|
|
175
344
|
static get log() {
|
|
176
|
-
return Logger.
|
|
345
|
+
return Logger.getLoggerForIdentifier("default").log;
|
|
177
346
|
}
|
|
178
347
|
/**
|
|
179
348
|
* Set the log formatter for the default logger.
|
|
180
349
|
*
|
|
181
350
|
* @param logFormatter
|
|
351
|
+
*
|
|
352
|
+
* @deprecated use {@link destinations}
|
|
182
353
|
*/
|
|
183
354
|
static set logFormatter(logFormatter) {
|
|
184
355
|
Logger.setLogFormatterForLogger("default", logFormatter);
|
|
185
356
|
}
|
|
186
357
|
/**
|
|
187
358
|
* Get the log formatter for the default logger.
|
|
359
|
+
*
|
|
360
|
+
* @deprecated use {@link destinations}
|
|
188
361
|
*/
|
|
189
362
|
static get logFormatter() {
|
|
190
|
-
return Logger.
|
|
363
|
+
return Logger.getLoggerForIdentifier("default").logFormatter;
|
|
191
364
|
}
|
|
192
365
|
/**
|
|
193
366
|
* Set logFormatter using configuration-style format name for the logger with the matching identifier.
|
|
194
367
|
*
|
|
195
368
|
* @param identifier The identifier of the logger
|
|
196
369
|
* @param format the name of the formatter (see Format enum)
|
|
370
|
+
*
|
|
371
|
+
* @deprecated use {@link destinations}
|
|
197
372
|
*/
|
|
198
373
|
static setFormatForLogger(identifier, format) {
|
|
199
|
-
|
|
200
|
-
if (logger) {
|
|
201
|
-
logger.logFormatter = logFormatterFor(format);
|
|
202
|
-
} else {
|
|
203
|
-
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
204
|
-
}
|
|
374
|
+
this.getLoggerForIdentifier(identifier).logFormatter = logFormatterFor(format);
|
|
205
375
|
}
|
|
206
376
|
/**
|
|
207
377
|
* Set default loglevel for the logger with the matching identifier.
|
|
208
378
|
*
|
|
209
379
|
* @param identifier The identifier of the logger
|
|
210
380
|
* @param level The level to set
|
|
381
|
+
*
|
|
382
|
+
* @deprecated use {@link destinations}
|
|
211
383
|
*/
|
|
212
384
|
static setDefaultLoglevelForLogger(identifier, level) {
|
|
213
|
-
|
|
214
|
-
if (logger) {
|
|
215
|
-
logger.defaultLogLevel = level;
|
|
216
|
-
} else {
|
|
217
|
-
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
218
|
-
}
|
|
385
|
+
this.getLoggerForIdentifier(identifier).defaultLogLevel = level;
|
|
219
386
|
}
|
|
220
387
|
/**
|
|
221
388
|
* Set facility loglevels for the logger with the matching identifier.
|
|
222
389
|
*
|
|
223
390
|
* @param identifier The identifier of the logger
|
|
224
391
|
* @param levels The levels to set
|
|
392
|
+
*
|
|
393
|
+
* @deprecated use {@link destinations}
|
|
225
394
|
*/
|
|
226
395
|
static setLogLevelsForLogger(identifier, levels) {
|
|
227
|
-
|
|
228
|
-
if (logger) {
|
|
229
|
-
logger.logLevels = levels;
|
|
230
|
-
} else {
|
|
231
|
-
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
232
|
-
}
|
|
396
|
+
this.getLoggerForIdentifier(identifier).logLevels = levels;
|
|
233
397
|
}
|
|
234
398
|
/**
|
|
235
399
|
* Set the log function for the logger with the matching identifier.
|
|
236
400
|
*
|
|
237
401
|
* @param identifier The identifier of the logger
|
|
238
402
|
* @param log The log function to set
|
|
403
|
+
*
|
|
404
|
+
* @deprecated use {@link destinations}
|
|
239
405
|
*/
|
|
240
406
|
static setLogger(identifier, log) {
|
|
241
|
-
|
|
242
|
-
if (logger) {
|
|
243
|
-
logger.log = log;
|
|
244
|
-
} else {
|
|
245
|
-
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
246
|
-
}
|
|
407
|
+
this.getLoggerForIdentifier(identifier).log = log;
|
|
247
408
|
}
|
|
248
409
|
/**
|
|
249
410
|
* Set the log formatter for the logger with the matching identifier.
|
|
250
411
|
*
|
|
251
412
|
* @param identifier The identifier of the logger
|
|
252
413
|
* @param logFormatter The log formatter to set
|
|
253
|
-
*/
|
|
254
|
-
static setLogFormatterForLogger(identifier, logFormatter) {
|
|
255
|
-
const logger = Logger.logger.find((logger2) => logger2.logIdentifier === identifier);
|
|
256
|
-
if (logger) {
|
|
257
|
-
logger.logFormatter = logFormatter;
|
|
258
|
-
} else {
|
|
259
|
-
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Create a new facility.
|
|
264
|
-
*
|
|
265
|
-
* @param name the name of the facility
|
|
266
|
-
* @returns a new facility
|
|
267
|
-
*/
|
|
268
|
-
static get(name) {
|
|
269
|
-
return new Logger(name);
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Stringify a value (BigInt aware) as JSON.
|
|
273
|
-
*
|
|
274
|
-
* @param data the value to stringify
|
|
275
|
-
* @returns the stringified value
|
|
276
|
-
*/
|
|
277
|
-
static toJSON(data) {
|
|
278
|
-
return JSON.stringify(data, (_, value) => {
|
|
279
|
-
if (typeof value === "bigint") {
|
|
280
|
-
return value.toString();
|
|
281
|
-
}
|
|
282
|
-
if (value instanceof Uint8Array) {
|
|
283
|
-
return import_Bytes.Bytes.toHex(value);
|
|
284
|
-
}
|
|
285
|
-
if (value === void 0) {
|
|
286
|
-
return "undefined";
|
|
287
|
-
}
|
|
288
|
-
return value;
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Mask a string with a given character. If unmaskedLength is provided then these number of characters will be
|
|
293
|
-
* shown unmasked.
|
|
294
|
-
*
|
|
295
|
-
* @param str String to mask
|
|
296
|
-
* @param maskChar character to mask with
|
|
297
|
-
* @param unmaskedLength number of characters to show unmasked in the beginning
|
|
298
|
-
*/
|
|
299
|
-
static maskString(str, maskChar = "*", unmaskedLength) {
|
|
300
|
-
return str.substring(0, unmaskedLength ?? 0) + str.substring(unmaskedLength ?? 0).replace(/./g, maskChar);
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Perform operations in a nested logging context. Messages will be
|
|
304
|
-
* indented while the context executes.
|
|
305
|
-
*/
|
|
306
|
-
static nest(context) {
|
|
307
|
-
this.nestingLevel++;
|
|
308
|
-
try {
|
|
309
|
-
return context();
|
|
310
|
-
} finally {
|
|
311
|
-
this.nestingLevel--;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Async version of nest().
|
|
316
|
-
*/
|
|
317
|
-
static async nestAsync(context) {
|
|
318
|
-
this.nestingLevel++;
|
|
319
|
-
try {
|
|
320
|
-
return await context();
|
|
321
|
-
} finally {
|
|
322
|
-
this.nestingLevel--;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Unhandled error reporter.
|
|
327
414
|
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
* To ensure these details are always recorded somewhere, unhandled errors may be reported here.
|
|
331
|
-
*
|
|
332
|
-
* To disable this behavior replace this function.
|
|
333
|
-
*/
|
|
334
|
-
static reportUnhandledError(error) {
|
|
335
|
-
try {
|
|
336
|
-
Logger.get("Logger").fatal("Unhandled error detected:", error);
|
|
337
|
-
} catch (e) {
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Invoke logic and return any log messages produced.
|
|
415
|
+
* @deprecated use {@link destinations}
|
|
342
416
|
*/
|
|
343
|
-
static
|
|
344
|
-
|
|
345
|
-
throw new Error("No logger loaded, cannot capture logs");
|
|
346
|
-
}
|
|
347
|
-
const logger = Logger.getLoggerforIdentifier(fromLogger);
|
|
348
|
-
const actualLogSettings = {
|
|
349
|
-
logFormatter: logger.logFormatter,
|
|
350
|
-
log: logger.log,
|
|
351
|
-
defaultLogLevel: logger.defaultLogLevel,
|
|
352
|
-
logLevels: { ...logger.logLevels }
|
|
353
|
-
};
|
|
354
|
-
try {
|
|
355
|
-
Logger.setFormatForLogger(fromLogger, import_LogFormat.LogFormat.PLAIN);
|
|
356
|
-
const captured = new Array();
|
|
357
|
-
Logger.setLogger(
|
|
358
|
-
fromLogger,
|
|
359
|
-
(level, message) => captured.push({
|
|
360
|
-
level,
|
|
361
|
-
message: message.replace(/\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d/, "xxxx-xx-xx xx:xx:xx.xxx")
|
|
362
|
-
})
|
|
363
|
-
);
|
|
364
|
-
fn();
|
|
365
|
-
return captured;
|
|
366
|
-
} finally {
|
|
367
|
-
Logger.setLogFormatterForLogger(fromLogger, actualLogSettings.logFormatter);
|
|
368
|
-
Logger.setDefaultLoglevelForLogger(fromLogger, actualLogSettings.defaultLogLevel);
|
|
369
|
-
Logger.setLogLevelsForLogger(fromLogger, actualLogSettings.logLevels);
|
|
370
|
-
Logger.setLogger(fromLogger, actualLogSettings.log);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
constructor(name) {
|
|
374
|
-
this.#name = name;
|
|
375
|
-
}
|
|
376
|
-
debug = (...values) => this.#log(import_LogLevel.LogLevel.DEBUG, values);
|
|
377
|
-
info = (...values) => this.#log(import_LogLevel.LogLevel.INFO, values);
|
|
378
|
-
notice = (...values) => this.#log(import_LogLevel.LogLevel.NOTICE, values);
|
|
379
|
-
warn = (...values) => this.#log(import_LogLevel.LogLevel.WARN, values);
|
|
380
|
-
error = (...values) => this.#log(import_LogLevel.LogLevel.ERROR, values);
|
|
381
|
-
fatal = (...values) => this.#log(import_LogLevel.LogLevel.FATAL, values);
|
|
382
|
-
log = (level, ...values) => this.#log(level, values);
|
|
383
|
-
#log(level, values) {
|
|
384
|
-
for (const logger of Logger.logger) {
|
|
385
|
-
if (level < (logger.logLevels[this.#name] ?? logger.defaultLogLevel)) {
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
if (!logger.context) {
|
|
389
|
-
logger.context = import_Diagnostic.Diagnostic.Context();
|
|
390
|
-
}
|
|
391
|
-
logger.context.run(
|
|
392
|
-
() => logger.log(level, logger.logFormatter(import_Time.Time.now(), level, this.#name, nestingPrefix(), values))
|
|
393
|
-
);
|
|
394
|
-
}
|
|
417
|
+
static setLogFormatterForLogger(identifier, logFormatter) {
|
|
418
|
+
this.getLoggerForIdentifier(identifier).logFormatter = logFormatter;
|
|
395
419
|
}
|
|
396
420
|
}
|
|
397
421
|
function nestingPrefix() {
|
|
@@ -401,17 +425,46 @@ function nestingPrefix() {
|
|
|
401
425
|
return "";
|
|
402
426
|
}
|
|
403
427
|
import_Boot.Boot.init(() => {
|
|
404
|
-
Logger.
|
|
405
|
-
logIdentifier: "default",
|
|
406
|
-
logFormatter: import_LogFormat.LogFormat.plain,
|
|
407
|
-
log: consoleLogger,
|
|
408
|
-
defaultLogLevel: import_LogLevel.LogLevel.DEBUG,
|
|
409
|
-
logLevels: {}
|
|
410
|
-
});
|
|
428
|
+
Logger.destinations = (0, import_LogDestination.LogDestinations)();
|
|
411
429
|
Logger.nestingLevel = 0;
|
|
412
430
|
if (typeof MatterHooks !== "undefined") {
|
|
413
431
|
MatterHooks.loggerSetup?.(Logger);
|
|
414
432
|
}
|
|
415
433
|
});
|
|
416
434
|
import_Cancelable.CancelablePromise.logger = Logger.get("CancelablePromise");
|
|
435
|
+
function logFormatterFor(formatName) {
|
|
436
|
+
const format = (0, import_LogFormat.LogFormat)(formatName);
|
|
437
|
+
return (now, level, facility, prefix, ...values) => format(import_Diagnostic.Diagnostic.message({ now, level, facility, prefix, values }));
|
|
438
|
+
}
|
|
439
|
+
function adaptDestinationToLegacy(destination) {
|
|
440
|
+
return {
|
|
441
|
+
get logIdentifier() {
|
|
442
|
+
return destination.name;
|
|
443
|
+
},
|
|
444
|
+
get logFormatter() {
|
|
445
|
+
return (now, level, facility, prefix, values) => destination.format(import_Diagnostic.Diagnostic.message({ now, level, facility, prefix, values }));
|
|
446
|
+
},
|
|
447
|
+
set logFormatter(logFormatter) {
|
|
448
|
+
destination.format = (message) => logFormatter(message.now, message.level, message.facility, message.prefix, message.values);
|
|
449
|
+
},
|
|
450
|
+
get log() {
|
|
451
|
+
return (level, formattedLog, facility) => destination.write(formattedLog, import_Diagnostic.Diagnostic.message({ level, facility }));
|
|
452
|
+
},
|
|
453
|
+
set log(log) {
|
|
454
|
+
destination.write = (text, message) => log(message.level, text, message.facility);
|
|
455
|
+
},
|
|
456
|
+
get defaultLogLevel() {
|
|
457
|
+
return destination.level;
|
|
458
|
+
},
|
|
459
|
+
set defaultLogLevel(level) {
|
|
460
|
+
destination.level = level;
|
|
461
|
+
},
|
|
462
|
+
get logLevels() {
|
|
463
|
+
return destination.facilityLevels;
|
|
464
|
+
},
|
|
465
|
+
set logLevels(levels) {
|
|
466
|
+
destination.facilityLevels = levels;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}
|
|
417
470
|
//# sourceMappingURL=Logger.js.map
|