@itwin/core-bentley 3.5.0-dev.4 → 3.5.0-dev.43

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