@itwin/core-bentley 4.0.0-dev.22 → 4.0.0-dev.23

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