@itwin/core-bentley 4.0.0-dev.7 → 4.0.0-dev.72
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 +50 -1
- package/lib/cjs/AccessToken.d.ts +10 -10
- package/lib/cjs/AccessToken.d.ts.map +1 -1
- package/lib/cjs/AccessToken.js +9 -9
- package/lib/cjs/Assert.d.ts +25 -25
- package/lib/cjs/Assert.js +45 -45
- package/lib/cjs/Assert.js.map +1 -1
- package/lib/cjs/BeEvent.d.ts +81 -81
- package/lib/cjs/BeEvent.d.ts.map +1 -1
- package/lib/cjs/BeEvent.js +156 -156
- package/lib/cjs/BeSQLite.d.ts +172 -170
- package/lib/cjs/BeSQLite.d.ts.map +1 -1
- package/lib/cjs/BeSQLite.js +185 -183
- package/lib/cjs/BeSQLite.js.map +1 -1
- package/lib/cjs/BentleyError.d.ts +378 -378
- package/lib/cjs/BentleyError.d.ts.map +1 -1
- package/lib/cjs/BentleyError.js +703 -702
- package/lib/cjs/BentleyError.js.map +1 -1
- package/lib/cjs/BentleyLoggerCategory.d.ts +11 -11
- package/lib/cjs/BentleyLoggerCategory.js +19 -19
- package/lib/cjs/ByteStream.d.ts +110 -110
- package/lib/cjs/ByteStream.js +159 -159
- package/lib/cjs/ClassUtils.d.ts +14 -14
- package/lib/cjs/ClassUtils.js +27 -27
- package/lib/cjs/Compare.d.ts +47 -47
- package/lib/cjs/Compare.d.ts.map +1 -1
- package/lib/cjs/Compare.js +75 -75
- package/lib/cjs/CompressedId64Set.d.ts +134 -134
- package/lib/cjs/CompressedId64Set.d.ts.map +1 -1
- package/lib/cjs/CompressedId64Set.js +428 -428
- package/lib/cjs/CompressedId64Set.js.map +1 -1
- package/lib/cjs/Dictionary.d.ts +125 -125
- package/lib/cjs/Dictionary.js +203 -203
- package/lib/cjs/Disposable.d.ts +80 -80
- package/lib/cjs/Disposable.d.ts.map +1 -1
- package/lib/cjs/Disposable.js +120 -120
- package/lib/cjs/Id.d.ts +285 -285
- package/lib/cjs/Id.d.ts.map +1 -1
- package/lib/cjs/Id.js +643 -643
- package/lib/cjs/IndexMap.d.ts +65 -65
- package/lib/cjs/IndexMap.js +91 -91
- package/lib/cjs/JsonSchema.d.ts +77 -77
- package/lib/cjs/JsonSchema.d.ts.map +1 -1
- package/lib/cjs/JsonSchema.js +9 -9
- package/lib/cjs/JsonUtils.d.ts +78 -78
- package/lib/cjs/JsonUtils.js +151 -151
- package/lib/cjs/LRUMap.d.ts +129 -129
- package/lib/cjs/LRUMap.js +333 -333
- package/lib/cjs/LRUMap.js.map +1 -1
- package/lib/cjs/Logger.d.ts +143 -143
- package/lib/cjs/Logger.d.ts.map +1 -1
- package/lib/cjs/Logger.js +256 -258
- package/lib/cjs/Logger.js.map +1 -1
- package/lib/cjs/ObservableSet.d.ts +23 -23
- package/lib/cjs/ObservableSet.js +51 -51
- package/lib/cjs/OneAtATimeAction.d.ts +31 -31
- package/lib/cjs/OneAtATimeAction.js +94 -94
- package/lib/cjs/OneAtATimeAction.js.map +1 -1
- package/lib/cjs/OrderedId64Iterable.d.ts +74 -74
- package/lib/cjs/OrderedId64Iterable.d.ts.map +1 -1
- package/lib/cjs/OrderedId64Iterable.js +235 -235
- package/lib/cjs/OrderedSet.d.ts +40 -40
- package/lib/cjs/OrderedSet.js +64 -64
- package/lib/cjs/PriorityQueue.d.ts +70 -70
- package/lib/cjs/PriorityQueue.d.ts.map +1 -1
- package/lib/cjs/PriorityQueue.js +140 -140
- package/lib/cjs/ProcessDetector.d.ts +59 -59
- package/lib/cjs/ProcessDetector.js +71 -71
- package/lib/cjs/SortedArray.d.ts +236 -232
- package/lib/cjs/SortedArray.d.ts.map +1 -1
- package/lib/cjs/SortedArray.js +315 -303
- package/lib/cjs/SortedArray.js.map +1 -1
- package/lib/cjs/StatusCategory.d.ts +30 -30
- package/lib/cjs/StatusCategory.d.ts.map +1 -1
- package/lib/cjs/StatusCategory.js +460 -460
- package/lib/cjs/StatusCategory.js.map +1 -1
- package/lib/cjs/StringUtils.d.ts +22 -22
- package/lib/cjs/StringUtils.js +148 -148
- package/lib/cjs/Time.d.ts +122 -122
- package/lib/cjs/Time.js +152 -152
- package/lib/cjs/Time.js.map +1 -1
- package/lib/cjs/Tracing.d.ts +43 -40
- package/lib/cjs/Tracing.d.ts.map +1 -1
- package/lib/cjs/Tracing.js +134 -130
- package/lib/cjs/Tracing.js.map +1 -1
- package/lib/cjs/TupleKeyedMap.d.ts +36 -36
- package/lib/cjs/TupleKeyedMap.js +102 -102
- package/lib/cjs/TypedArrayBuilder.d.ts +155 -155
- package/lib/cjs/TypedArrayBuilder.d.ts.map +1 -1
- package/lib/cjs/TypedArrayBuilder.js +206 -208
- package/lib/cjs/TypedArrayBuilder.js.map +1 -1
- package/lib/cjs/UnexpectedErrors.d.ts +43 -43
- package/lib/cjs/UnexpectedErrors.d.ts.map +1 -1
- package/lib/cjs/UnexpectedErrors.js +68 -68
- package/lib/cjs/UnexpectedErrors.js.map +1 -1
- package/lib/cjs/UtilityTypes.d.ts +112 -96
- package/lib/cjs/UtilityTypes.d.ts.map +1 -1
- package/lib/cjs/UtilityTypes.js +40 -40
- package/lib/cjs/UtilityTypes.js.map +1 -1
- package/lib/cjs/YieldManager.d.ts +18 -18
- package/lib/cjs/YieldManager.js +34 -34
- package/lib/cjs/core-bentley.d.ts +74 -74
- package/lib/cjs/core-bentley.js +94 -90
- package/lib/cjs/core-bentley.js.map +1 -1
- package/lib/cjs/partitionArray.d.ts +21 -21
- package/lib/cjs/partitionArray.js +43 -43
- package/lib/esm/AccessToken.d.ts +10 -10
- package/lib/esm/AccessToken.d.ts.map +1 -1
- package/lib/esm/AccessToken.js +8 -8
- package/lib/esm/Assert.d.ts +25 -25
- package/lib/esm/Assert.js +41 -41
- package/lib/esm/Assert.js.map +1 -1
- package/lib/esm/BeEvent.d.ts +81 -81
- package/lib/esm/BeEvent.d.ts.map +1 -1
- package/lib/esm/BeEvent.js +150 -150
- package/lib/esm/BeSQLite.d.ts +172 -170
- package/lib/esm/BeSQLite.d.ts.map +1 -1
- package/lib/esm/BeSQLite.js +182 -180
- package/lib/esm/BeSQLite.js.map +1 -1
- package/lib/esm/BentleyError.d.ts +378 -378
- package/lib/esm/BentleyError.d.ts.map +1 -1
- package/lib/esm/BentleyError.js +699 -698
- package/lib/esm/BentleyError.js.map +1 -1
- package/lib/esm/BentleyLoggerCategory.d.ts +11 -11
- package/lib/esm/BentleyLoggerCategory.js +16 -16
- package/lib/esm/ByteStream.d.ts +110 -110
- package/lib/esm/ByteStream.js +155 -155
- package/lib/esm/ClassUtils.d.ts +14 -14
- package/lib/esm/ClassUtils.js +22 -22
- package/lib/esm/Compare.d.ts +47 -47
- package/lib/esm/Compare.d.ts.map +1 -1
- package/lib/esm/Compare.js +63 -63
- package/lib/esm/CompressedId64Set.d.ts +134 -134
- package/lib/esm/CompressedId64Set.d.ts.map +1 -1
- package/lib/esm/CompressedId64Set.js +423 -423
- package/lib/esm/CompressedId64Set.js.map +1 -1
- package/lib/esm/Dictionary.d.ts +125 -125
- package/lib/esm/Dictionary.js +199 -199
- package/lib/esm/Disposable.d.ts +80 -80
- package/lib/esm/Disposable.d.ts.map +1 -1
- package/lib/esm/Disposable.js +112 -112
- package/lib/esm/Id.d.ts +285 -285
- package/lib/esm/Id.d.ts.map +1 -1
- package/lib/esm/Id.js +639 -639
- package/lib/esm/IndexMap.d.ts +65 -65
- package/lib/esm/IndexMap.js +86 -86
- package/lib/esm/JsonSchema.d.ts +77 -77
- package/lib/esm/JsonSchema.d.ts.map +1 -1
- package/lib/esm/JsonSchema.js +8 -8
- package/lib/esm/JsonUtils.d.ts +78 -78
- package/lib/esm/JsonUtils.js +148 -148
- package/lib/esm/LRUMap.d.ts +129 -129
- package/lib/esm/LRUMap.js +326 -326
- package/lib/esm/LRUMap.js.map +1 -1
- package/lib/esm/Logger.d.ts +143 -143
- package/lib/esm/Logger.d.ts.map +1 -1
- package/lib/esm/Logger.js +253 -253
- package/lib/esm/Logger.js.map +1 -1
- package/lib/esm/ObservableSet.d.ts +23 -23
- package/lib/esm/ObservableSet.js +47 -47
- package/lib/esm/OneAtATimeAction.d.ts +31 -31
- package/lib/esm/OneAtATimeAction.js +89 -89
- package/lib/esm/OneAtATimeAction.js.map +1 -1
- package/lib/esm/OrderedId64Iterable.d.ts +74 -74
- package/lib/esm/OrderedId64Iterable.d.ts.map +1 -1
- package/lib/esm/OrderedId64Iterable.js +232 -232
- package/lib/esm/OrderedSet.d.ts +40 -40
- package/lib/esm/OrderedSet.js +59 -59
- package/lib/esm/PriorityQueue.d.ts +70 -70
- package/lib/esm/PriorityQueue.d.ts.map +1 -1
- package/lib/esm/PriorityQueue.js +136 -136
- package/lib/esm/ProcessDetector.d.ts +59 -59
- package/lib/esm/ProcessDetector.js +67 -67
- package/lib/esm/SortedArray.d.ts +236 -232
- package/lib/esm/SortedArray.d.ts.map +1 -1
- package/lib/esm/SortedArray.js +308 -296
- package/lib/esm/SortedArray.js.map +1 -1
- package/lib/esm/StatusCategory.d.ts +30 -30
- package/lib/esm/StatusCategory.d.ts.map +1 -1
- package/lib/esm/StatusCategory.js +455 -454
- package/lib/esm/StatusCategory.js.map +1 -1
- package/lib/esm/StringUtils.d.ts +22 -22
- package/lib/esm/StringUtils.js +142 -142
- package/lib/esm/Time.d.ts +122 -122
- package/lib/esm/Time.js +146 -146
- package/lib/esm/Time.js.map +1 -1
- package/lib/esm/Tracing.d.ts +43 -40
- package/lib/esm/Tracing.d.ts.map +1 -1
- package/lib/esm/Tracing.js +130 -126
- package/lib/esm/Tracing.js.map +1 -1
- package/lib/esm/TupleKeyedMap.d.ts +36 -36
- package/lib/esm/TupleKeyedMap.js +98 -98
- package/lib/esm/TypedArrayBuilder.d.ts +155 -155
- package/lib/esm/TypedArrayBuilder.d.ts.map +1 -1
- package/lib/esm/TypedArrayBuilder.js +198 -200
- package/lib/esm/TypedArrayBuilder.js.map +1 -1
- package/lib/esm/UnexpectedErrors.d.ts +43 -43
- package/lib/esm/UnexpectedErrors.d.ts.map +1 -1
- package/lib/esm/UnexpectedErrors.js +65 -64
- package/lib/esm/UnexpectedErrors.js.map +1 -1
- package/lib/esm/UtilityTypes.d.ts +112 -96
- package/lib/esm/UtilityTypes.d.ts.map +1 -1
- package/lib/esm/UtilityTypes.js +34 -34
- package/lib/esm/UtilityTypes.js.map +1 -1
- package/lib/esm/YieldManager.d.ts +18 -18
- package/lib/esm/YieldManager.js +30 -30
- package/lib/esm/core-bentley.d.ts +74 -74
- package/lib/esm/core-bentley.js +78 -78
- package/lib/esm/partitionArray.d.ts +21 -21
- package/lib/esm/partitionArray.js +39 -39
- package/package.json +9 -9
package/lib/cjs/Logger.js
CHANGED
|
@@ -1,259 +1,257 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
/** @packageDocumentation
|
|
7
|
-
* @module Logging
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.PerfLogger = exports.Logger = exports.LogLevel = void 0;
|
|
11
|
-
const BentleyError_1 = require("./BentleyError");
|
|
12
|
-
const BentleyLoggerCategory_1 = require("./BentleyLoggerCategory");
|
|
13
|
-
/** Use to categorize logging messages by severity.
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
var LogLevel;
|
|
17
|
-
(function (LogLevel) {
|
|
18
|
-
/** Tracing and debugging - low level */
|
|
19
|
-
LogLevel[LogLevel["Trace"] = 0] = "Trace";
|
|
20
|
-
/** Information - mid level */
|
|
21
|
-
LogLevel[LogLevel["Info"] = 1] = "Info";
|
|
22
|
-
/** Warnings - high level */
|
|
23
|
-
LogLevel[LogLevel["Warning"] = 2] = "Warning";
|
|
24
|
-
/** Errors - highest level */
|
|
25
|
-
LogLevel[LogLevel["Error"] = 3] = "Error";
|
|
26
|
-
/** Higher than any real logging level. This is used to turn a category off. */
|
|
27
|
-
LogLevel[LogLevel["None"] = 4] = "None";
|
|
28
|
-
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
29
|
-
/** Logger allows libraries and apps to report potentially useful information about operations, and it allows apps and users to control
|
|
30
|
-
* how or if the logged information is displayed or collected. See [Learning about Logging]($docs/learning/common/Logging.md).
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
class Logger {
|
|
34
|
-
/** Initialize the logger streams. Should be called at application initialization time. */
|
|
35
|
-
static initialize(logError, logWarning, logInfo, logTrace) {
|
|
36
|
-
Logger._logError = logError;
|
|
37
|
-
Logger._logWarning = logWarning;
|
|
38
|
-
Logger._logInfo = logInfo;
|
|
39
|
-
Logger._logTrace = logTrace;
|
|
40
|
-
Logger.turnOffLevelDefault();
|
|
41
|
-
Logger.turnOffCategories();
|
|
42
|
-
}
|
|
43
|
-
/** Initialize the logger to output to the console. */
|
|
44
|
-
static initializeToConsole() {
|
|
45
|
-
const logConsole = (level) => (category, message, metaData) => console.log(`${level} | ${category} | ${message} ${Logger.stringifyMetaData(metaData)}`); // eslint-disable-line no-console
|
|
46
|
-
Logger.initialize(logConsole("Error"), logConsole("Warning"), logConsole("Info"), logConsole("Trace"));
|
|
47
|
-
}
|
|
48
|
-
/** merge the supplied metadata with all static metadata into one object */
|
|
49
|
-
static getMetaData(metaData) {
|
|
50
|
-
const metaObj = {};
|
|
51
|
-
for (const meta of Logger.staticMetaData) {
|
|
52
|
-
const val = BentleyError_1.BentleyError.getMetaData(meta[1]);
|
|
53
|
-
if (val)
|
|
54
|
-
Object.assign(metaObj, val);
|
|
55
|
-
}
|
|
56
|
-
Object.assign(metaObj, BentleyError_1.BentleyError.getMetaData(metaData)); // do this last so user supplied values take precedence
|
|
57
|
-
return metaObj;
|
|
58
|
-
}
|
|
59
|
-
/** stringify the metadata for a log message by merging the supplied metadata with all static metadata into one object that is then `JSON.stringify`ed. */
|
|
60
|
-
static stringifyMetaData(metaData) {
|
|
61
|
-
const metaObj = this.getMetaData(metaData);
|
|
62
|
-
return Object.keys(metaObj).length > 0 ? JSON.stringify(metaObj) : "";
|
|
63
|
-
}
|
|
64
|
-
/** Set the least severe level at which messages should be displayed by default. Call setLevel to override this default setting for specific categories. */
|
|
65
|
-
static setLevelDefault(minLevel) {
|
|
66
|
-
|
|
67
|
-
this.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
case "
|
|
82
|
-
case "
|
|
83
|
-
case "
|
|
84
|
-
case "
|
|
85
|
-
case "
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (!
|
|
122
|
-
throw new BentleyError_1.BentleyError(BentleyError_1.IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item must be a
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
* @param
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* @param
|
|
175
|
-
* @param
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
* @param
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
* @param
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
* @param
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
Logger.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
* It
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
exports.PerfLogger = PerfLogger;
|
|
258
|
-
PerfLogger._severity = LogLevel.Info;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Logging
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.PerfLogger = exports.Logger = exports.LogLevel = void 0;
|
|
11
|
+
const BentleyError_1 = require("./BentleyError");
|
|
12
|
+
const BentleyLoggerCategory_1 = require("./BentleyLoggerCategory");
|
|
13
|
+
/** Use to categorize logging messages by severity.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
var LogLevel;
|
|
17
|
+
(function (LogLevel) {
|
|
18
|
+
/** Tracing and debugging - low level */
|
|
19
|
+
LogLevel[LogLevel["Trace"] = 0] = "Trace";
|
|
20
|
+
/** Information - mid level */
|
|
21
|
+
LogLevel[LogLevel["Info"] = 1] = "Info";
|
|
22
|
+
/** Warnings - high level */
|
|
23
|
+
LogLevel[LogLevel["Warning"] = 2] = "Warning";
|
|
24
|
+
/** Errors - highest level */
|
|
25
|
+
LogLevel[LogLevel["Error"] = 3] = "Error";
|
|
26
|
+
/** Higher than any real logging level. This is used to turn a category off. */
|
|
27
|
+
LogLevel[LogLevel["None"] = 4] = "None";
|
|
28
|
+
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
29
|
+
/** Logger allows libraries and apps to report potentially useful information about operations, and it allows apps and users to control
|
|
30
|
+
* how or if the logged information is displayed or collected. See [Learning about Logging]($docs/learning/common/Logging.md).
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
class Logger {
|
|
34
|
+
/** Initialize the logger streams. Should be called at application initialization time. */
|
|
35
|
+
static initialize(logError, logWarning, logInfo, logTrace) {
|
|
36
|
+
Logger._logError = logError;
|
|
37
|
+
Logger._logWarning = logWarning;
|
|
38
|
+
Logger._logInfo = logInfo;
|
|
39
|
+
Logger._logTrace = logTrace;
|
|
40
|
+
Logger.turnOffLevelDefault();
|
|
41
|
+
Logger.turnOffCategories();
|
|
42
|
+
}
|
|
43
|
+
/** Initialize the logger to output to the console. */
|
|
44
|
+
static initializeToConsole() {
|
|
45
|
+
const logConsole = (level) => (category, message, metaData) => console.log(`${level} | ${category} | ${message} ${Logger.stringifyMetaData(metaData)}`); // eslint-disable-line no-console
|
|
46
|
+
Logger.initialize(logConsole("Error"), logConsole("Warning"), logConsole("Info"), logConsole("Trace"));
|
|
47
|
+
}
|
|
48
|
+
/** merge the supplied metadata with all static metadata into one object */
|
|
49
|
+
static getMetaData(metaData) {
|
|
50
|
+
const metaObj = {};
|
|
51
|
+
for (const meta of Logger.staticMetaData) {
|
|
52
|
+
const val = BentleyError_1.BentleyError.getMetaData(meta[1]);
|
|
53
|
+
if (val)
|
|
54
|
+
Object.assign(metaObj, val);
|
|
55
|
+
}
|
|
56
|
+
Object.assign(metaObj, BentleyError_1.BentleyError.getMetaData(metaData)); // do this last so user supplied values take precedence
|
|
57
|
+
return metaObj;
|
|
58
|
+
}
|
|
59
|
+
/** stringify the metadata for a log message by merging the supplied metadata with all static metadata into one object that is then `JSON.stringify`ed. */
|
|
60
|
+
static stringifyMetaData(metaData) {
|
|
61
|
+
const metaObj = this.getMetaData(metaData);
|
|
62
|
+
return Object.keys(metaObj).length > 0 ? JSON.stringify(metaObj) : "";
|
|
63
|
+
}
|
|
64
|
+
/** Set the least severe level at which messages should be displayed by default. Call setLevel to override this default setting for specific categories. */
|
|
65
|
+
static setLevelDefault(minLevel) {
|
|
66
|
+
this._minLevel = minLevel;
|
|
67
|
+
this.logLevelChangedFn?.();
|
|
68
|
+
}
|
|
69
|
+
/** Set the minimum logging level for the specified category. The minimum level is least severe level at which messages in the
|
|
70
|
+
* specified category should be displayed.
|
|
71
|
+
*/
|
|
72
|
+
static setLevel(category, minLevel) {
|
|
73
|
+
Logger._categoryFilter.set(category, minLevel);
|
|
74
|
+
this.logLevelChangedFn?.();
|
|
75
|
+
}
|
|
76
|
+
/** Interpret a string as the name of a LogLevel */
|
|
77
|
+
static parseLogLevel(str) {
|
|
78
|
+
switch (str.toUpperCase()) {
|
|
79
|
+
case "EXCEPTION": return LogLevel.Error;
|
|
80
|
+
case "FATAL": return LogLevel.Error;
|
|
81
|
+
case "ERROR": return LogLevel.Error;
|
|
82
|
+
case "WARNING": return LogLevel.Warning;
|
|
83
|
+
case "INFO": return LogLevel.Info;
|
|
84
|
+
case "TRACE": return LogLevel.Trace;
|
|
85
|
+
case "DEBUG": return LogLevel.Trace;
|
|
86
|
+
}
|
|
87
|
+
return LogLevel.None;
|
|
88
|
+
}
|
|
89
|
+
/** Set the log level for multiple categories at once. Also see [[validateProps]] */
|
|
90
|
+
static configureLevels(cfg) {
|
|
91
|
+
Logger.validateProps(cfg);
|
|
92
|
+
if (cfg.defaultLevel !== undefined) {
|
|
93
|
+
this.setLevelDefault(Logger.parseLogLevel(cfg.defaultLevel));
|
|
94
|
+
}
|
|
95
|
+
if (cfg.categoryLevels !== undefined) {
|
|
96
|
+
for (const cl of cfg.categoryLevels) {
|
|
97
|
+
this.setLevel(cl.category, Logger.parseLogLevel(cl.logLevel));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
static isLogLevel(v) {
|
|
102
|
+
return LogLevel.hasOwnProperty(v);
|
|
103
|
+
}
|
|
104
|
+
/** Check that the specified object is a valid LoggerLevelsConfig. This is useful when reading a config from a .json file. */
|
|
105
|
+
static validateProps(config) {
|
|
106
|
+
const validProps = ["defaultLevel", "categoryLevels"];
|
|
107
|
+
for (const prop of Object.keys(config)) {
|
|
108
|
+
if (!validProps.includes(prop))
|
|
109
|
+
throw new BentleyError_1.BentleyError(BentleyError_1.IModelStatus.BadArg, `LoggerLevelsConfig - unrecognized property: ${prop}`);
|
|
110
|
+
if (prop === "defaultLevel") {
|
|
111
|
+
if (!Logger.isLogLevel(config.defaultLevel))
|
|
112
|
+
throw new BentleyError_1.BentleyError(BentleyError_1.IModelStatus.BadArg, `LoggerLevelsConfig.defaultLevel must be a LogLevel. Invalid value: ${JSON.stringify(config.defaultLevel)}`);
|
|
113
|
+
}
|
|
114
|
+
else if (prop === "categoryLevels") {
|
|
115
|
+
const value = config[prop];
|
|
116
|
+
if (!Array.isArray(value))
|
|
117
|
+
throw new BentleyError_1.BentleyError(BentleyError_1.IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels must be an array. Invalid value: ${JSON.stringify(value)}`);
|
|
118
|
+
for (const item of config[prop]) {
|
|
119
|
+
if (!item.hasOwnProperty("category") || !item.hasOwnProperty("logLevel"))
|
|
120
|
+
throw new BentleyError_1.BentleyError(BentleyError_1.IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item must be a LoggerCategoryAndLevel {category: logLevel:}. Invalid value: ${JSON.stringify(item)}`);
|
|
121
|
+
if (!Logger.isLogLevel(item.logLevel))
|
|
122
|
+
throw new BentleyError_1.BentleyError(BentleyError_1.IModelStatus.BadArg, `LoggerLevelsConfig.categoryLevels - each item's logLevel property must be a LogLevel. Invalid value: ${JSON.stringify(item.logLevel)}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Get the minimum logging level for the specified category. */
|
|
128
|
+
static getLevel(category) {
|
|
129
|
+
// Prefer the level set for this category specifically
|
|
130
|
+
const minLevelForThisCategory = Logger._categoryFilter.get(category);
|
|
131
|
+
if (minLevelForThisCategory !== undefined)
|
|
132
|
+
return minLevelForThisCategory;
|
|
133
|
+
// Fall back on the level set for the parent of this category.
|
|
134
|
+
const parent = category.lastIndexOf(".");
|
|
135
|
+
if (parent !== -1)
|
|
136
|
+
return Logger.getLevel(category.slice(0, parent));
|
|
137
|
+
// Fall back on the default level.
|
|
138
|
+
return Logger._minLevel;
|
|
139
|
+
}
|
|
140
|
+
/** Turns off the least severe level at which messages should be displayed by default.
|
|
141
|
+
* This turns off logging for all messages for which no category minimum level is defined.
|
|
142
|
+
*/
|
|
143
|
+
static turnOffLevelDefault() {
|
|
144
|
+
Logger._minLevel = undefined;
|
|
145
|
+
}
|
|
146
|
+
/** Turns off all category level filters previously defined with [[Logger.setLevel]].
|
|
147
|
+
*/
|
|
148
|
+
static turnOffCategories() {
|
|
149
|
+
Logger._categoryFilter.clear();
|
|
150
|
+
}
|
|
151
|
+
/** Check if messages in the specified category should be displayed at this level of severity. */
|
|
152
|
+
static isEnabled(category, level) {
|
|
153
|
+
const minLevel = Logger.getLevel(category);
|
|
154
|
+
return (minLevel !== undefined) && (level >= minLevel);
|
|
155
|
+
}
|
|
156
|
+
/** Log the specified message to the **error** stream.
|
|
157
|
+
* @param category The category of the message.
|
|
158
|
+
* @param message The message.
|
|
159
|
+
* @param metaData Optional data for the message
|
|
160
|
+
*/
|
|
161
|
+
static logError(category, message, metaData) {
|
|
162
|
+
if (Logger._logError && Logger.isEnabled(category, LogLevel.Error))
|
|
163
|
+
Logger._logError(category, message, metaData);
|
|
164
|
+
}
|
|
165
|
+
static getExceptionMessage(err) {
|
|
166
|
+
const stack = Logger.logExceptionCallstacks ? `\n${BentleyError_1.BentleyError.getErrorStack(err)}` : "";
|
|
167
|
+
return BentleyError_1.BentleyError.getErrorMessage(err) + stack;
|
|
168
|
+
}
|
|
169
|
+
/** Log the specified exception. The special "ExceptionType" property will be added as metadata,
|
|
170
|
+
* in addition to any other metadata that may be supplied by the caller, unless the
|
|
171
|
+
* metadata supplied by the caller already includes this property.
|
|
172
|
+
* @param category The category of the message.
|
|
173
|
+
* @param err The exception object.
|
|
174
|
+
* @param log The logger output function to use - defaults to Logger.logError
|
|
175
|
+
* @param metaData Optional data for the message
|
|
176
|
+
*/
|
|
177
|
+
static logException(category, err, log = Logger.logError) {
|
|
178
|
+
log(category, Logger.getExceptionMessage(err), () => {
|
|
179
|
+
return { ...BentleyError_1.BentleyError.getErrorMetadata(err), exceptionType: err.constructor.name };
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/** Log the specified message to the **warning** stream.
|
|
183
|
+
* @param category The category of the message.
|
|
184
|
+
* @param message The message.
|
|
185
|
+
* @param metaData Optional data for the message
|
|
186
|
+
*/
|
|
187
|
+
static logWarning(category, message, metaData) {
|
|
188
|
+
if (Logger._logWarning && Logger.isEnabled(category, LogLevel.Warning))
|
|
189
|
+
Logger._logWarning(category, message, metaData);
|
|
190
|
+
}
|
|
191
|
+
/** Log the specified message to the **info** stream.
|
|
192
|
+
* @param category The category of the message.
|
|
193
|
+
* @param message The message.
|
|
194
|
+
* @param metaData Optional data for the message
|
|
195
|
+
*/
|
|
196
|
+
static logInfo(category, message, metaData) {
|
|
197
|
+
if (Logger._logInfo && Logger.isEnabled(category, LogLevel.Info))
|
|
198
|
+
Logger._logInfo(category, message, metaData);
|
|
199
|
+
}
|
|
200
|
+
/** Log the specified message to the **trace** stream.
|
|
201
|
+
* @param category The category of the message.
|
|
202
|
+
* @param message The message.
|
|
203
|
+
* @param metaData Optional data for the message
|
|
204
|
+
*/
|
|
205
|
+
static logTrace(category, message, metaData) {
|
|
206
|
+
if (Logger._logTrace && Logger.isEnabled(category, LogLevel.Trace))
|
|
207
|
+
Logger._logTrace(category, message, metaData);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
Logger._categoryFilter = new Map(); // do not change the name of this member, it is referenced directly from node addon
|
|
211
|
+
Logger._minLevel = undefined; // do not change the name of this member, it is referenced directly from node addon
|
|
212
|
+
/** Should the call stack be included when an exception is logged? */
|
|
213
|
+
Logger.logExceptionCallstacks = false;
|
|
214
|
+
/** All static metadata is combined with per-call metadata and stringified in every log message.
|
|
215
|
+
* Static metadata can either be an object or a function that returns an object.
|
|
216
|
+
* Use a key to identify entries in the map so the can be removed individually.
|
|
217
|
+
* @internal */
|
|
218
|
+
Logger.staticMetaData = new Map();
|
|
219
|
+
exports.Logger = Logger;
|
|
220
|
+
/** Simple performance diagnostics utility.
|
|
221
|
+
* It measures the time from construction to disposal. On disposal it logs the routine name along with
|
|
222
|
+
* the duration in milliseconds.
|
|
223
|
+
* It also logs the routine name at construction time so that nested calls can be disambiguated.
|
|
224
|
+
*
|
|
225
|
+
* The timings are logged using the log category **Performance** and log severity [[LogLevel.INFO]].
|
|
226
|
+
* Enable those, if you want to capture timings.
|
|
227
|
+
* @public
|
|
228
|
+
*/
|
|
229
|
+
class PerfLogger {
|
|
230
|
+
constructor(operation, metaData) {
|
|
231
|
+
this._operation = operation;
|
|
232
|
+
this._metaData = metaData;
|
|
233
|
+
if (!Logger.isEnabled(BentleyLoggerCategory_1.BentleyLoggerCategory.Performance, PerfLogger._severity)) {
|
|
234
|
+
this._startTimeStamp = 0;
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
Logger.logInfo(BentleyLoggerCategory_1.BentleyLoggerCategory.Performance, `${this._operation},START`, this._metaData);
|
|
238
|
+
this._startTimeStamp = new Date().getTime(); // take timestamp
|
|
239
|
+
}
|
|
240
|
+
logMessage() {
|
|
241
|
+
const endTimeStamp = new Date().getTime();
|
|
242
|
+
if (!Logger.isEnabled(BentleyLoggerCategory_1.BentleyLoggerCategory.Performance, PerfLogger._severity))
|
|
243
|
+
return;
|
|
244
|
+
Logger.logInfo(BentleyLoggerCategory_1.BentleyLoggerCategory.Performance, `${this._operation},END`, () => {
|
|
245
|
+
const mdata = this._metaData ? BentleyError_1.BentleyError.getMetaData(this._metaData) : {};
|
|
246
|
+
return {
|
|
247
|
+
...mdata, TimeElapsed: endTimeStamp - this._startTimeStamp, // eslint-disable-line @typescript-eslint/naming-convention
|
|
248
|
+
};
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
dispose() {
|
|
252
|
+
this.logMessage();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
PerfLogger._severity = LogLevel.Info;
|
|
256
|
+
exports.PerfLogger = PerfLogger;
|
|
259
257
|
//# sourceMappingURL=Logger.js.map
|