@itwin/core-bentley 3.4.0-dev.9 → 3.5.0-dev.5

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