@itwin/core-bentley 4.0.0-dev.8 → 4.0.0-dev.81

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