@itwin/core-bentley 4.0.0-dev.7 → 4.0.0-dev.70

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