@itwin/core-bentley 4.0.0-dev.52 → 4.0.0-dev.54

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