@itwin/core-bentley 4.0.0-dev.48 → 4.0.0-dev.51

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