@firebase/logger 0.2.6-eap-storage-emulator.ed256f582 → 0.3.0

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.
package/CHANGELOG.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # @firebase/logger
2
2
 
3
- ## 0.2.6
4
- ### Patch Changes
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
5
6
 
7
+ - [`a99943fe3`](https://github.com/firebase/firebase-js-sdk/commit/a99943fe3bd5279761aa29d138ec91272b06df39) [#5539](https://github.com/firebase/firebase-js-sdk/pull/5539) - Use esm2017 builds by default
6
8
 
9
+ ## 0.2.6
10
+
11
+ ### Patch Changes
7
12
 
8
13
  - [`a754645e`](https://github.com/firebase/firebase-js-sdk/commit/a754645ec2be1b8c205f25f510196eee298b0d6e) [#3297](https://github.com/firebase/firebase-js-sdk/pull/3297) Thanks [@renovate](https://github.com/apps/renovate)! - Update dependency typescript to v3.9.5
package/dist/index.cjs.js CHANGED
@@ -2,28 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /*! *****************************************************************************
6
- Copyright (c) Microsoft Corporation.
7
-
8
- Permission to use, copy, modify, and/or distribute this software for any
9
- purpose with or without fee is hereby granted.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- PERFORMANCE OF THIS SOFTWARE.
18
- ***************************************************************************** */
19
-
20
- function __spreadArrays() {
21
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
22
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
23
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
24
- r[k] = a[j];
25
- return r;
26
- }
5
+ var tslib = require('tslib');
27
6
 
28
7
  /**
29
8
  * @license
@@ -46,6 +25,18 @@ var _a;
46
25
  * A container for all of the Logger instances
47
26
  */
48
27
  var instances = [];
28
+ /**
29
+ * The JS SDK supports 5 log levels and also allows a user the ability to
30
+ * silence the logs altogether.
31
+ *
32
+ * The order is a follows:
33
+ * DEBUG < VERBOSE < INFO < WARN < ERROR
34
+ *
35
+ * All of the log types above the current log level will be captured (i.e. if
36
+ * you set the log level to `INFO`, errors will still be logged, but `DEBUG` and
37
+ * `VERBOSE` logs will not)
38
+ */
39
+ exports.LogLevel = void 0;
49
40
  (function (LogLevel) {
50
41
  LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
51
42
  LogLevel[LogLevel["VERBOSE"] = 1] = "VERBOSE";
@@ -95,7 +86,7 @@ var defaultLogHandler = function (instance, logType) {
95
86
  var now = new Date().toISOString();
96
87
  var method = ConsoleMethod[logType];
97
88
  if (method) {
98
- console[method].apply(console, __spreadArrays(["[" + now + "] " + instance.name + ":"], args));
89
+ console[method].apply(console, tslib.__spreadArray(["[" + now + "] " + instance.name + ":"], args));
99
90
  }
100
91
  else {
101
92
  throw new Error("Attempted to log a message with an invalid logType (value: " + logType + ")");
@@ -176,40 +167,40 @@ var Logger = /** @class */ (function () {
176
167
  for (var _i = 0; _i < arguments.length; _i++) {
177
168
  args[_i] = arguments[_i];
178
169
  }
179
- this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, exports.LogLevel.DEBUG], args));
180
- this._logHandler.apply(this, __spreadArrays([this, exports.LogLevel.DEBUG], args));
170
+ this._userLogHandler && this._userLogHandler.apply(this, tslib.__spreadArray([this, exports.LogLevel.DEBUG], args));
171
+ this._logHandler.apply(this, tslib.__spreadArray([this, exports.LogLevel.DEBUG], args));
181
172
  };
182
173
  Logger.prototype.log = function () {
183
174
  var args = [];
184
175
  for (var _i = 0; _i < arguments.length; _i++) {
185
176
  args[_i] = arguments[_i];
186
177
  }
187
- this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, exports.LogLevel.VERBOSE], args));
188
- this._logHandler.apply(this, __spreadArrays([this, exports.LogLevel.VERBOSE], args));
178
+ this._userLogHandler && this._userLogHandler.apply(this, tslib.__spreadArray([this, exports.LogLevel.VERBOSE], args));
179
+ this._logHandler.apply(this, tslib.__spreadArray([this, exports.LogLevel.VERBOSE], args));
189
180
  };
190
181
  Logger.prototype.info = function () {
191
182
  var args = [];
192
183
  for (var _i = 0; _i < arguments.length; _i++) {
193
184
  args[_i] = arguments[_i];
194
185
  }
195
- this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, exports.LogLevel.INFO], args));
196
- this._logHandler.apply(this, __spreadArrays([this, exports.LogLevel.INFO], args));
186
+ this._userLogHandler && this._userLogHandler.apply(this, tslib.__spreadArray([this, exports.LogLevel.INFO], args));
187
+ this._logHandler.apply(this, tslib.__spreadArray([this, exports.LogLevel.INFO], args));
197
188
  };
198
189
  Logger.prototype.warn = function () {
199
190
  var args = [];
200
191
  for (var _i = 0; _i < arguments.length; _i++) {
201
192
  args[_i] = arguments[_i];
202
193
  }
203
- this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, exports.LogLevel.WARN], args));
204
- this._logHandler.apply(this, __spreadArrays([this, exports.LogLevel.WARN], args));
194
+ this._userLogHandler && this._userLogHandler.apply(this, tslib.__spreadArray([this, exports.LogLevel.WARN], args));
195
+ this._logHandler.apply(this, tslib.__spreadArray([this, exports.LogLevel.WARN], args));
205
196
  };
206
197
  Logger.prototype.error = function () {
207
198
  var args = [];
208
199
  for (var _i = 0; _i < arguments.length; _i++) {
209
200
  args[_i] = arguments[_i];
210
201
  }
211
- this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, exports.LogLevel.ERROR], args));
212
- this._logHandler.apply(this, __spreadArrays([this, exports.LogLevel.ERROR], args));
202
+ this._userLogHandler && this._userLogHandler.apply(this, tslib.__spreadArray([this, exports.LogLevel.ERROR], args));
203
+ this._logHandler.apply(this, tslib.__spreadArray([this, exports.LogLevel.ERROR], args));
213
204
  };
214
205
  return Logger;
215
206
  }());
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/logger.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type LogLevelString =\n | 'debug'\n | 'verbose'\n | 'info'\n | 'warn'\n | 'error'\n | 'silent';\n\nexport interface LogOptions {\n level: LogLevelString;\n}\n\nexport type LogCallback = (callbackParams: LogCallbackParams) => void;\n\nexport interface LogCallbackParams {\n level: LogLevelString;\n message: string;\n args: unknown[];\n type: string;\n}\n\n/**\n * A container for all of the Logger instances\n */\nexport const instances: Logger[] = [];\n\n/**\n * The JS SDK supports 5 log levels and also allows a user the ability to\n * silence the logs altogether.\n *\n * The order is a follows:\n * DEBUG < VERBOSE < INFO < WARN < ERROR\n *\n * All of the log types above the current log level will be captured (i.e. if\n * you set the log level to `INFO`, errors will still be logged, but `DEBUG` and\n * `VERBOSE` logs will not)\n */\nexport enum LogLevel {\n DEBUG,\n VERBOSE,\n INFO,\n WARN,\n ERROR,\n SILENT\n}\n\nconst levelStringToEnum: { [key in LogLevelString]: LogLevel } = {\n 'debug': LogLevel.DEBUG,\n 'verbose': LogLevel.VERBOSE,\n 'info': LogLevel.INFO,\n 'warn': LogLevel.WARN,\n 'error': LogLevel.ERROR,\n 'silent': LogLevel.SILENT\n};\n\n/**\n * The default log level\n */\nconst defaultLogLevel: LogLevel = LogLevel.INFO;\n\n/**\n * We allow users the ability to pass their own log handler. We will pass the\n * type of log, the current log level, and any other arguments passed (i.e. the\n * messages that the user wants to log) to this function.\n */\nexport type LogHandler = (\n loggerInstance: Logger,\n logType: LogLevel,\n ...args: unknown[]\n) => void;\n\n/**\n * By default, `console.debug` is not displayed in the developer console (in\n * chrome). To avoid forcing users to have to opt-in to these logs twice\n * (i.e. once for firebase, and once in the console), we are sending `DEBUG`\n * logs to the `console.log` function.\n */\nconst ConsoleMethod = {\n [LogLevel.DEBUG]: 'log',\n [LogLevel.VERBOSE]: 'log',\n [LogLevel.INFO]: 'info',\n [LogLevel.WARN]: 'warn',\n [LogLevel.ERROR]: 'error'\n};\n\n/**\n * The default log handler will forward DEBUG, VERBOSE, INFO, WARN, and ERROR\n * messages on to their corresponding console counterparts (if the log method\n * is supported by the current log level)\n */\nconst defaultLogHandler: LogHandler = (instance, logType, ...args): void => {\n if (logType < instance.logLevel) {\n return;\n }\n const now = new Date().toISOString();\n const method = ConsoleMethod[logType as keyof typeof ConsoleMethod];\n if (method) {\n console[method as 'log' | 'info' | 'warn' | 'error'](\n `[${now}] ${instance.name}:`,\n ...args\n );\n } else {\n throw new Error(\n `Attempted to log a message with an invalid logType (value: ${logType})`\n );\n }\n};\n\nexport class Logger {\n /**\n * Gives you an instance of a Logger to capture messages according to\n * Firebase's logging scheme.\n *\n * @param name The name that the logs will be associated with\n */\n constructor(public name: string) {\n /**\n * Capture the current instance for later use\n */\n instances.push(this);\n }\n\n /**\n * The log level of the given Logger instance.\n */\n private _logLevel = defaultLogLevel;\n\n get logLevel(): LogLevel {\n return this._logLevel;\n }\n\n set logLevel(val: LogLevel) {\n if (!(val in LogLevel)) {\n throw new TypeError(`Invalid value \"${val}\" assigned to \\`logLevel\\``);\n }\n this._logLevel = val;\n }\n\n // Workaround for setter/getter having to be the same type.\n setLogLevel(val: LogLevel | LogLevelString): void {\n this._logLevel = typeof val === 'string' ? levelStringToEnum[val] : val;\n }\n\n /**\n * The main (internal) log handler for the Logger instance.\n * Can be set to a new function in internal package code but not by user.\n */\n private _logHandler: LogHandler = defaultLogHandler;\n get logHandler(): LogHandler {\n return this._logHandler;\n }\n set logHandler(val: LogHandler) {\n if (typeof val !== 'function') {\n throw new TypeError('Value assigned to `logHandler` must be a function');\n }\n this._logHandler = val;\n }\n\n /**\n * The optional, additional, user-defined log handler for the Logger instance.\n */\n private _userLogHandler: LogHandler | null = null;\n get userLogHandler(): LogHandler | null {\n return this._userLogHandler;\n }\n set userLogHandler(val: LogHandler | null) {\n this._userLogHandler = val;\n }\n\n /**\n * The functions below are all based on the `console` interface\n */\n\n debug(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.DEBUG, ...args);\n this._logHandler(this, LogLevel.DEBUG, ...args);\n }\n log(...args: unknown[]): void {\n this._userLogHandler &&\n this._userLogHandler(this, LogLevel.VERBOSE, ...args);\n this._logHandler(this, LogLevel.VERBOSE, ...args);\n }\n info(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.INFO, ...args);\n this._logHandler(this, LogLevel.INFO, ...args);\n }\n warn(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.WARN, ...args);\n this._logHandler(this, LogLevel.WARN, ...args);\n }\n error(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.ERROR, ...args);\n this._logHandler(this, LogLevel.ERROR, ...args);\n }\n}\n\nexport function setLogLevel(level: LogLevelString | LogLevel): void {\n instances.forEach(inst => {\n inst.setLogLevel(level);\n });\n}\n\nexport function setUserLogHandler(\n logCallback: LogCallback | null,\n options?: LogOptions\n): void {\n for (const instance of instances) {\n let customLogLevel: LogLevel | null = null;\n if (options && options.level) {\n customLogLevel = levelStringToEnum[options.level];\n }\n if (logCallback === null) {\n instance.userLogHandler = null;\n } else {\n instance.userLogHandler = (\n instance: Logger,\n level: LogLevel,\n ...args: unknown[]\n ) => {\n const message = args\n .map(arg => {\n if (arg == null) {\n return null;\n } else if (typeof arg === 'string') {\n return arg;\n } else if (typeof arg === 'number' || typeof arg === 'boolean') {\n return arg.toString();\n } else if (arg instanceof Error) {\n return arg.message;\n } else {\n try {\n return JSON.stringify(arg);\n } catch (ignored) {\n return null;\n }\n }\n })\n .filter(arg => arg)\n .join(' ');\n if (level >= (customLogLevel ?? instance.logLevel)) {\n logCallback({\n level: LogLevel[level].toLowerCase() as LogLevelString,\n message,\n args,\n type: instance.name\n });\n }\n };\n }\n }\n}\n"],"names":["LogLevel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;AAsCA;;;AAGO,IAAM,SAAS,GAAa,EAAE,CAAC;AAatC,WAAY,QAAQ;IAClB,yCAAK,CAAA;IACL,6CAAO,CAAA;IACP,uCAAI,CAAA;IACJ,uCAAI,CAAA;IACJ,yCAAK,CAAA;IACL,2CAAM,CAAA;AACR,CAAC,EAPWA,gBAAQ,KAARA,gBAAQ,QAOnB;AAED,IAAM,iBAAiB,GAA0C;IAC/D,OAAO,EAAEA,gBAAQ,CAAC,KAAK;IACvB,SAAS,EAAEA,gBAAQ,CAAC,OAAO;IAC3B,MAAM,EAAEA,gBAAQ,CAAC,IAAI;IACrB,MAAM,EAAEA,gBAAQ,CAAC,IAAI;IACrB,OAAO,EAAEA,gBAAQ,CAAC,KAAK;IACvB,QAAQ,EAAEA,gBAAQ,CAAC,MAAM;CAC1B,CAAC;AAEF;;;AAGA,IAAM,eAAe,GAAaA,gBAAQ,CAAC,IAAI,CAAC;AAahD;;;;;;AAMA,IAAM,aAAa;IACjB,GAACA,gBAAQ,CAAC,KAAK,IAAG,KAAK;IACvB,GAACA,gBAAQ,CAAC,OAAO,IAAG,KAAK;IACzB,GAACA,gBAAQ,CAAC,IAAI,I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S,EAAT,IAAS;QAA3B,IAAM,QAAQ,kBAAA;gBAAR,QAAQ;KA2ClB;AACH;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/logger.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type LogLevelString =\n | 'debug'\n | 'verbose'\n | 'info'\n | 'warn'\n | 'error'\n | 'silent';\n\nexport interface LogOptions {\n level: LogLevelString;\n}\n\nexport type LogCallback = (callbackParams: LogCallbackParams) => void;\n\nexport interface LogCallbackParams {\n level: LogLevelString;\n message: string;\n args: unknown[];\n type: string;\n}\n\n/**\n * A container for all of the Logger instances\n */\nexport const instances: Logger[] = [];\n\n/**\n * The JS SDK supports 5 log levels and also allows a user the ability to\n * silence the logs altogether.\n *\n * The order is a follows:\n * DEBUG < VERBOSE < INFO < WARN < ERROR\n *\n * All of the log types above the current log level will be captured (i.e. if\n * you set the log level to `INFO`, errors will still be logged, but `DEBUG` and\n * `VERBOSE` logs will not)\n */\nexport enum LogLevel {\n DEBUG,\n VERBOSE,\n INFO,\n WARN,\n ERROR,\n SILENT\n}\n\nconst levelStringToEnum: { [key in LogLevelString]: LogLevel } = {\n 'debug': LogLevel.DEBUG,\n 'verbose': LogLevel.VERBOSE,\n 'info': LogLevel.INFO,\n 'warn': LogLevel.WARN,\n 'error': LogLevel.ERROR,\n 'silent': LogLevel.SILENT\n};\n\n/**\n * The default log level\n */\nconst defaultLogLevel: LogLevel = LogLevel.INFO;\n\n/**\n * We allow users the ability to pass their own log handler. We will pass the\n * type of log, the current log level, and any other arguments passed (i.e. the\n * messages that the user wants to log) to this function.\n */\nexport type LogHandler = (\n loggerInstance: Logger,\n logType: LogLevel,\n ...args: unknown[]\n) => void;\n\n/**\n * By default, `console.debug` is not displayed in the developer console (in\n * chrome). To avoid forcing users to have to opt-in to these logs twice\n * (i.e. once for firebase, and once in the console), we are sending `DEBUG`\n * logs to the `console.log` function.\n */\nconst ConsoleMethod = {\n [LogLevel.DEBUG]: 'log',\n [LogLevel.VERBOSE]: 'log',\n [LogLevel.INFO]: 'info',\n [LogLevel.WARN]: 'warn',\n [LogLevel.ERROR]: 'error'\n};\n\n/**\n * The default log handler will forward DEBUG, VERBOSE, INFO, WARN, and ERROR\n * messages on to their corresponding console counterparts (if the log method\n * is supported by the current log level)\n */\nconst defaultLogHandler: LogHandler = (instance, logType, ...args): void => {\n if (logType < instance.logLevel) {\n return;\n }\n const now = new Date().toISOString();\n const method = ConsoleMethod[logType as keyof typeof ConsoleMethod];\n if (method) {\n console[method as 'log' | 'info' | 'warn' | 'error'](\n `[${now}] ${instance.name}:`,\n ...args\n );\n } else {\n throw new Error(\n `Attempted to log a message with an invalid logType (value: ${logType})`\n );\n }\n};\n\nexport class Logger {\n /**\n * Gives you an instance of a Logger to capture messages according to\n * Firebase's logging scheme.\n *\n * @param name The name that the logs will be associated with\n */\n constructor(public name: string) {\n /**\n * Capture the current instance for later use\n */\n instances.push(this);\n }\n\n /**\n * The log level of the given Logger instance.\n */\n private _logLevel = defaultLogLevel;\n\n get logLevel(): LogLevel {\n return this._logLevel;\n }\n\n set logLevel(val: LogLevel) {\n if (!(val in LogLevel)) {\n throw new TypeError(`Invalid value \"${val}\" assigned to \\`logLevel\\``);\n }\n this._logLevel = val;\n }\n\n // Workaround for setter/getter having to be the same type.\n setLogLevel(val: LogLevel | LogLevelString): void {\n this._logLevel = typeof val === 'string' ? levelStringToEnum[val] : val;\n }\n\n /**\n * The main (internal) log handler for the Logger instance.\n * Can be set to a new function in internal package code but not by user.\n */\n private _logHandler: LogHandler = defaultLogHandler;\n get logHandler(): LogHandler {\n return this._logHandler;\n }\n set logHandler(val: LogHandler) {\n if (typeof val !== 'function') {\n throw new TypeError('Value assigned to `logHandler` must be a function');\n }\n this._logHandler = val;\n }\n\n /**\n * The optional, additional, user-defined log handler for the Logger instance.\n */\n private _userLogHandler: LogHandler | null = null;\n get userLogHandler(): LogHandler | null {\n return this._userLogHandler;\n }\n set userLogHandler(val: LogHandler | null) {\n this._userLogHandler = val;\n }\n\n /**\n * The functions below are all based on the `console` interface\n */\n\n debug(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.DEBUG, ...args);\n this._logHandler(this, LogLevel.DEBUG, ...args);\n }\n log(...args: unknown[]): void {\n this._userLogHandler &&\n this._userLogHandler(this, LogLevel.VERBOSE, ...args);\n this._logHandler(this, LogLevel.VERBOSE, ...args);\n }\n info(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.INFO, ...args);\n this._logHandler(this, LogLevel.INFO, ...args);\n }\n warn(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.WARN, ...args);\n this._logHandler(this, LogLevel.WARN, ...args);\n }\n error(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.ERROR, ...args);\n this._logHandler(this, LogLevel.ERROR, ...args);\n }\n}\n\nexport function setLogLevel(level: LogLevelString | LogLevel): void {\n instances.forEach(inst => {\n inst.setLogLevel(level);\n });\n}\n\nexport function setUserLogHandler(\n logCallback: LogCallback | null,\n options?: LogOptions\n): void {\n for (const instance of instances) {\n let customLogLevel: LogLevel | null = null;\n if (options && options.level) {\n customLogLevel = levelStringToEnum[options.level];\n }\n if (logCallback === null) {\n instance.userLogHandler = null;\n } else {\n instance.userLogHandler = (\n instance: Logger,\n level: LogLevel,\n ...args: unknown[]\n ) => {\n const message = args\n .map(arg => {\n if (arg == null) {\n return null;\n } else if (typeof arg === 'string') {\n return arg;\n } else if (typeof arg === 'number' || typeof arg === 'boolean') {\n return arg.toString();\n } else if (arg instanceof Error) {\n return arg.message;\n } else {\n try {\n return JSON.stringify(arg);\n } catch (ignored) {\n return null;\n }\n }\n })\n .filter(arg => arg)\n .join(' ');\n if (level >= (customLogLevel ?? instance.logLevel)) {\n logCallback({\n level: LogLevel[level].toLowerCase() as LogLevelString,\n message,\n args,\n type: instance.name\n });\n }\n };\n }\n }\n}\n"],"names":["LogLevel"],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;AAsCA;;;AAGO,IAAM,SAAS,GAAa,EAAE,CAAC;AAEtC;;;;;;;;;;;AAWYA;AAAZ,WAAY,QAAQ;IAClB,yCAAK,CAAA;IACL,6CAAO,CAAA;IACP,uCAAI,CAAA;IACJ,uCAAI,CAAA;IACJ,yCAAK,CAAA;IACL,2CAAM,CAAA;AACR,CAAC,EAPWA,gBAAQ,KAARA,gBAAQ,QAOnB;AAED,IAAM,iBAAiB,GAA0C;IAC/D,OAAO,EAAEA,gBAAQ,CAAC,KAAK;IACvB,SAAS,EAAEA,gBAAQ,CAAC,OAAO;IAC3B,MAAM,EAAEA,gBAAQ,CAAC,IAAI;IACrB,MAAM,EAAEA,gBAAQ,CAAC,IAAI;IACrB,OAAO,EAAEA,gBAAQ,CAAC,KAAK;IACvB,QAAQ,EAAEA,gBAAQ,CAAC,MAAM;CAC1B,CAAC;AAEF;;;AAGA,IAAM,eAAe,GAAaA,gBAAQ,CAAC,IAAI,CAAC;AAahD;;;;;;AAMA,IAAM,aAAa;IACjB,GAACA,gBAAQ,CAAC,KAAK,IAAG,KAAK;IACvB,GAACA,gBAAQ,CAAC,OAAO,IAAG,KAAK;IACzB,GAACA,gBAAQ,CAAC,IAAI,IAAG,MAAM;IACvB,GAACA,gBAAQ,CAAC,IAAI,IAAG,MAAM;IACvB,GAACA,gBAAQ,CAAC,KAAK,IAAG,OAAO;OAC1B,CAAC;AAEF;;;;;AAKA,IAAM,iBAAiB,GAAe,UAAC,QAAQ,EAAE,OAAO;IAAE,cAAO;SAAP,UAAO,EA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;oBAAlB,6BAAkB;;gBAElB,IAAM,OAAO,GAAG,IAAI;qBACjB,GAAG,CAAC,UAAA,GAAG;oBACN,IAAI,GAAG,IAAI,IAAI,EAAE;wBACf,OAAO,IAAI,CAAC;qBACb;yBAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;wBAClC,OAAO,GAAG,CAAC;qBACZ;yBAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE;wBAC9D,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;qBACvB;yBAAM,IAAI,GAAG,YAAY,KAAK,EAAE;wBAC/B,OAAO,GAAG,CAAC,OAAO,CAAC;qBACpB;yBAAM;wBACL,IAAI;4BACF,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;yBAC5B;wBAAC,OAAO,OAAO,EAAE;4BAChB,OAAO,IAAI,CAAC;yBACb;qBACF;iBACF,CAAC;qBACD,MAAM,CAAC,UAAA,GAAG,IAAI,OAAA,GAAG,GAAA,CAAC;qBAClB,IAAI,CAAC,GAAG,CAAC,CAAC;gBACb,IAAI,KAAK,KAAK,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE;oBAClD,WAAW,CAAC;wBACV,KAAK,EAAEA,gBAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAoB;wBACtD,OAAO,SAAA;wBACP,IAAI,MAAA;wBACJ,IAAI,EAAE,QAAQ,CAAC,IAAI;qBACpB,CAAC,CAAC;iBACJ;aACF,CAAC;SACH;;IA1CH,KAAuB,UAAS,EAAT,uBAAS,EAAT,uBAAS,EAAT,IAAS;QAA3B,IAAM,QAAQ,kBAAA;gBAAR,QAAQ;KA2ClB;AACH;;;;;;"}
@@ -1,25 +1,4 @@
1
- /*! *****************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
-
16
- function __spreadArrays() {
17
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
18
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
19
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
20
- r[k] = a[j];
21
- return r;
22
- }
1
+ import { __spreadArray } from 'tslib';
23
2
 
24
3
  /**
25
4
  * @license
@@ -103,7 +82,7 @@ var defaultLogHandler = function (instance, logType) {
103
82
  var now = new Date().toISOString();
104
83
  var method = ConsoleMethod[logType];
105
84
  if (method) {
106
- console[method].apply(console, __spreadArrays(["[" + now + "] " + instance.name + ":"], args));
85
+ console[method].apply(console, __spreadArray(["[" + now + "] " + instance.name + ":"], args));
107
86
  }
108
87
  else {
109
88
  throw new Error("Attempted to log a message with an invalid logType (value: " + logType + ")");
@@ -184,40 +163,40 @@ var Logger = /** @class */ (function () {
184
163
  for (var _i = 0; _i < arguments.length; _i++) {
185
164
  args[_i] = arguments[_i];
186
165
  }
187
- this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, LogLevel.DEBUG], args));
188
- this._logHandler.apply(this, __spreadArrays([this, LogLevel.DEBUG], args));
166
+ this._userLogHandler && this._userLogHandler.apply(this, __spreadArray([this, LogLevel.DEBUG], args));
167
+ this._logHandler.apply(this, __spreadArray([this, LogLevel.DEBUG], args));
189
168
  };
190
169
  Logger.prototype.log = function () {
191
170
  var args = [];
192
171
  for (var _i = 0; _i < arguments.length; _i++) {
193
172
  args[_i] = arguments[_i];
194
173
  }
195
- this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, LogLevel.VERBOSE], args));
196
- this._logHandler.apply(this, __spreadArrays([this, LogLevel.VERBOSE], args));
174
+ this._userLogHandler && this._userLogHandler.apply(this, __spreadArray([this, LogLevel.VERBOSE], args));
175
+ this._logHandler.apply(this, __spreadArray([this, LogLevel.VERBOSE], args));
197
176
  };
198
177
  Logger.prototype.info = function () {
199
178
  var args = [];
200
179
  for (var _i = 0; _i < arguments.length; _i++) {
201
180
  args[_i] = arguments[_i];
202
181
  }
203
- this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, LogLevel.INFO], args));
204
- this._logHandler.apply(this, __spreadArrays([this, LogLevel.INFO], args));
182
+ this._userLogHandler && this._userLogHandler.apply(this, __spreadArray([this, LogLevel.INFO], args));
183
+ this._logHandler.apply(this, __spreadArray([this, LogLevel.INFO], args));
205
184
  };
206
185
  Logger.prototype.warn = function () {
207
186
  var args = [];
208
187
  for (var _i = 0; _i < arguments.length; _i++) {
209
188
  args[_i] = arguments[_i];
210
189
  }
211
- this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, LogLevel.WARN], args));
212
- this._logHandler.apply(this, __spreadArrays([this, LogLevel.WARN], args));
190
+ this._userLogHandler && this._userLogHandler.apply(this, __spreadArray([this, LogLevel.WARN], args));
191
+ this._logHandler.apply(this, __spreadArray([this, LogLevel.WARN], args));
213
192
  };
214
193
  Logger.prototype.error = function () {
215
194
  var args = [];
216
195
  for (var _i = 0; _i < arguments.length; _i++) {
217
196
  args[_i] = arguments[_i];
218
197
  }
219
- this._userLogHandler && this._userLogHandler.apply(this, __spreadArrays([this, LogLevel.ERROR], args));
220
- this._logHandler.apply(this, __spreadArrays([this, LogLevel.ERROR], args));
198
+ this._userLogHandler && this._userLogHandler.apply(this, __spreadArray([this, LogLevel.ERROR], args));
199
+ this._logHandler.apply(this, __spreadArray([this, LogLevel.ERROR], args));
221
200
  };
222
201
  return Logger;
223
202
  }());
@@ -284,4 +263,4 @@ function setUserLogHandler(logCallback, options) {
284
263
  }
285
264
 
286
265
  export { LogLevel, Logger, setLogLevel, setUserLogHandler };
287
- //# sourceMappingURL=index.esm.js.map
266
+ //# sourceMappingURL=index.esm5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm5.js","sources":["../src/logger.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type LogLevelString =\n | 'debug'\n | 'verbose'\n | 'info'\n | 'warn'\n | 'error'\n | 'silent';\n\nexport interface LogOptions {\n level: LogLevelString;\n}\n\nexport type LogCallback = (callbackParams: LogCallbackParams) => void;\n\nexport interface LogCallbackParams {\n level: LogLevelString;\n message: string;\n args: unknown[];\n type: string;\n}\n\n/**\n * A container for all of the Logger instances\n */\nexport const instances: Logger[] = [];\n\n/**\n * The JS SDK supports 5 log levels and also allows a user the ability to\n * silence the logs altogether.\n *\n * The order is a follows:\n * DEBUG < VERBOSE < INFO < WARN < ERROR\n *\n * All of the log types above the current log level will be captured (i.e. if\n * you set the log level to `INFO`, errors will still be logged, but `DEBUG` and\n * `VERBOSE` logs will not)\n */\nexport enum LogLevel {\n DEBUG,\n VERBOSE,\n INFO,\n WARN,\n ERROR,\n SILENT\n}\n\nconst levelStringToEnum: { [key in LogLevelString]: LogLevel } = {\n 'debug': LogLevel.DEBUG,\n 'verbose': LogLevel.VERBOSE,\n 'info': LogLevel.INFO,\n 'warn': LogLevel.WARN,\n 'error': LogLevel.ERROR,\n 'silent': LogLevel.SILENT\n};\n\n/**\n * The default log level\n */\nconst defaultLogLevel: LogLevel = LogLevel.INFO;\n\n/**\n * We allow users the ability to pass their own log handler. We will pass the\n * type of log, the current log level, and any other arguments passed (i.e. the\n * messages that the user wants to log) to this function.\n */\nexport type LogHandler = (\n loggerInstance: Logger,\n logType: LogLevel,\n ...args: unknown[]\n) => void;\n\n/**\n * By default, `console.debug` is not displayed in the developer console (in\n * chrome). To avoid forcing users to have to opt-in to these logs twice\n * (i.e. once for firebase, and once in the console), we are sending `DEBUG`\n * logs to the `console.log` function.\n */\nconst ConsoleMethod = {\n [LogLevel.DEBUG]: 'log',\n [LogLevel.VERBOSE]: 'log',\n [LogLevel.INFO]: 'info',\n [LogLevel.WARN]: 'warn',\n [LogLevel.ERROR]: 'error'\n};\n\n/**\n * The default log handler will forward DEBUG, VERBOSE, INFO, WARN, and ERROR\n * messages on to their corresponding console counterparts (if the log method\n * is supported by the current log level)\n */\nconst defaultLogHandler: LogHandler = (instance, logType, ...args): void => {\n if (logType < instance.logLevel) {\n return;\n }\n const now = new Date().toISOString();\n const method = ConsoleMethod[logType as keyof typeof ConsoleMethod];\n if (method) {\n console[method as 'log' | 'info' | 'warn' | 'error'](\n `[${now}] ${instance.name}:`,\n ...args\n );\n } else {\n throw new Error(\n `Attempted to log a message with an invalid logType (value: ${logType})`\n );\n }\n};\n\nexport class Logger {\n /**\n * Gives you an instance of a Logger to capture messages according to\n * Firebase's logging scheme.\n *\n * @param name The name that the logs will be associated with\n */\n constructor(public name: string) {\n /**\n * Capture the current instance for later use\n */\n instances.push(this);\n }\n\n /**\n * The log level of the given Logger instance.\n */\n private _logLevel = defaultLogLevel;\n\n get logLevel(): LogLevel {\n return this._logLevel;\n }\n\n set logLevel(val: LogLevel) {\n if (!(val in LogLevel)) {\n throw new TypeError(`Invalid value \"${val}\" assigned to \\`logLevel\\``);\n }\n this._logLevel = val;\n }\n\n // Workaround for setter/getter having to be the same type.\n setLogLevel(val: LogLevel | LogLevelString): void {\n this._logLevel = typeof val === 'string' ? levelStringToEnum[val] : val;\n }\n\n /**\n * The main (internal) log handler for the Logger instance.\n * Can be set to a new function in internal package code but not by user.\n */\n private _logHandler: LogHandler = defaultLogHandler;\n get logHandler(): LogHandler {\n return this._logHandler;\n }\n set logHandler(val: LogHandler) {\n if (typeof val !== 'function') {\n throw new TypeError('Value assigned to `logHandler` must be a function');\n }\n this._logHandler = val;\n }\n\n /**\n * The optional, additional, user-defined log handler for the Logger instance.\n */\n private _userLogHandler: LogHandler | null = null;\n get userLogHandler(): LogHandler | null {\n return this._userLogHandler;\n }\n set userLogHandler(val: LogHandler | null) {\n this._userLogHandler = val;\n }\n\n /**\n * The functions below are all based on the `console` interface\n */\n\n debug(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.DEBUG, ...args);\n this._logHandler(this, LogLevel.DEBUG, ...args);\n }\n log(...args: unknown[]): void {\n this._userLogHandler &&\n this._userLogHandler(this, LogLevel.VERBOSE, ...args);\n this._logHandler(this, LogLevel.VERBOSE, ...args);\n }\n info(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.INFO, ...args);\n this._logHandler(this, LogLevel.INFO, ...args);\n }\n warn(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.WARN, ...args);\n this._logHandler(this, LogLevel.WARN, ...args);\n }\n error(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.ERROR, ...args);\n this._logHandler(this, LogLevel.ERROR, ...args);\n }\n}\n\nexport function setLogLevel(level: LogLevelString | LogLevel): void {\n instances.forEach(inst => {\n inst.setLogLevel(level);\n });\n}\n\nexport function setUserLogHandler(\n logCallback: LogCallback | null,\n options?: LogOptions\n): void {\n for (const instance of instances) {\n let customLogLevel: LogLevel | null = null;\n if (options && options.level) {\n customLogLevel = levelStringToEnum[options.level];\n }\n if (logCallback === null) {\n instance.userLogHandler = null;\n } else {\n instance.userLogHandler = (\n instance: Logger,\n level: LogLevel,\n ...args: unknown[]\n ) => {\n const message = args\n .map(arg => {\n if (arg == null) {\n return null;\n } else if (typeof arg === 'string') {\n return arg;\n } else if (typeof arg === 'number' || typeof arg === 'boolean') {\n return arg.toString();\n } else if (arg instanceof Error) {\n return arg.message;\n } else {\n try {\n return JSON.stringify(arg);\n } catch (ignored) {\n return null;\n }\n }\n })\n .filter(arg => arg)\n .join(' ');\n if (level >= (customLogLevel ?? instance.logLevel)) {\n logCallback({\n level: LogLevel[level].toLowerCase() as LogLevelString,\n message,\n args,\n type: instance.name\n });\n }\n };\n }\n }\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;AAsCA;;;AAGO,IAAM,SAAS,GAAa,EAAE,CAAC;AAEtC;;;;;;;;;;;IAWY;AAAZ,WAAY,QAAQ;IAClB,yCAAK,CAAA;IACL,6CAAO,CAAA;IACP,uCAAI,CAAA;IACJ,uCAAI,CAAA;IACJ,yCAAK,CAAA;IACL,2CAAM,CAAA;AACR,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;AAED,IAAM,iBAAiB,GAA0C;IAC/D,OAAO,EAAE,QAAQ,CAAC,KAAK;IACvB,SAAS,EAAE,QAAQ,CAAC,OAAO;IAC3B,MAAM,EAAE,QAAQ,CAAC,IAAI;IACrB,MAAM,EAAE,QAAQ,CAAC,IAAI;IACrB,OAAO,EAAE,QAAQ,CAAC,KAAK;IACvB,QAAQ,EAAE,QAAQ,CAAC,MAAM;CAC1B,CAAC;AAEF;;;AAGA,IAAM,eAAe,GAAa,QAAQ,CAAC,IAAI,CAAC;AAahD;;;;;;AAMA,IAAM,aAAa;IACjB,GAAC,QAAQ,CAAC,KAAK,IAAG,KAAK;IACvB,GAAC,QAAQ,CAAC,OAAO,IAAG,KAAK;IACzB,GAAC,QAAQ,CAAC,IAAI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AAQ,kBAAA;gBAAR,QAAQ;KA2ClB;AACH;;;;"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@firebase/logger",
3
- "version": "0.2.6-eap-storage-emulator.ed256f582",
3
+ "version": "0.3.0",
4
4
  "description": "A logger package for use in the Firebase JS SDK",
5
5
  "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
6
6
  "main": "dist/index.cjs.js",
7
- "module": "dist/index.esm.js",
8
- "esm2017": "dist/index.esm2017.js",
7
+ "module": "dist/index.esm2017.js",
8
+ "esm5": "dist/index.esm5.js",
9
9
  "files": [
10
10
  "dist"
11
11
  ],
@@ -23,10 +23,13 @@
23
23
  "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha test/**/*.test.* --config ../../config/mocharc.node.js"
24
24
  },
25
25
  "license": "Apache-2.0",
26
+ "dependencies": {
27
+ "tslib": "^2.1.0"
28
+ },
26
29
  "devDependencies": {
27
- "rollup": "2.35.1",
28
- "rollup-plugin-typescript2": "0.29.0",
29
- "typescript": "4.0.5"
30
+ "rollup": "2.56.3",
31
+ "rollup-plugin-typescript2": "0.30.0",
32
+ "typescript": "4.2.2"
30
33
  },
31
34
  "repository": {
32
35
  "directory": "packages/logger",
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/logger.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type LogLevelString =\n | 'debug'\n | 'verbose'\n | 'info'\n | 'warn'\n | 'error'\n | 'silent';\n\nexport interface LogOptions {\n level: LogLevelString;\n}\n\nexport type LogCallback = (callbackParams: LogCallbackParams) => void;\n\nexport interface LogCallbackParams {\n level: LogLevelString;\n message: string;\n args: unknown[];\n type: string;\n}\n\n/**\n * A container for all of the Logger instances\n */\nexport const instances: Logger[] = [];\n\n/**\n * The JS SDK supports 5 log levels and also allows a user the ability to\n * silence the logs altogether.\n *\n * The order is a follows:\n * DEBUG < VERBOSE < INFO < WARN < ERROR\n *\n * All of the log types above the current log level will be captured (i.e. if\n * you set the log level to `INFO`, errors will still be logged, but `DEBUG` and\n * `VERBOSE` logs will not)\n */\nexport enum LogLevel {\n DEBUG,\n VERBOSE,\n INFO,\n WARN,\n ERROR,\n SILENT\n}\n\nconst levelStringToEnum: { [key in LogLevelString]: LogLevel } = {\n 'debug': LogLevel.DEBUG,\n 'verbose': LogLevel.VERBOSE,\n 'info': LogLevel.INFO,\n 'warn': LogLevel.WARN,\n 'error': LogLevel.ERROR,\n 'silent': LogLevel.SILENT\n};\n\n/**\n * The default log level\n */\nconst defaultLogLevel: LogLevel = LogLevel.INFO;\n\n/**\n * We allow users the ability to pass their own log handler. We will pass the\n * type of log, the current log level, and any other arguments passed (i.e. the\n * messages that the user wants to log) to this function.\n */\nexport type LogHandler = (\n loggerInstance: Logger,\n logType: LogLevel,\n ...args: unknown[]\n) => void;\n\n/**\n * By default, `console.debug` is not displayed in the developer console (in\n * chrome). To avoid forcing users to have to opt-in to these logs twice\n * (i.e. once for firebase, and once in the console), we are sending `DEBUG`\n * logs to the `console.log` function.\n */\nconst ConsoleMethod = {\n [LogLevel.DEBUG]: 'log',\n [LogLevel.VERBOSE]: 'log',\n [LogLevel.INFO]: 'info',\n [LogLevel.WARN]: 'warn',\n [LogLevel.ERROR]: 'error'\n};\n\n/**\n * The default log handler will forward DEBUG, VERBOSE, INFO, WARN, and ERROR\n * messages on to their corresponding console counterparts (if the log method\n * is supported by the current log level)\n */\nconst defaultLogHandler: LogHandler = (instance, logType, ...args): void => {\n if (logType < instance.logLevel) {\n return;\n }\n const now = new Date().toISOString();\n const method = ConsoleMethod[logType as keyof typeof ConsoleMethod];\n if (method) {\n console[method as 'log' | 'info' | 'warn' | 'error'](\n `[${now}] ${instance.name}:`,\n ...args\n );\n } else {\n throw new Error(\n `Attempted to log a message with an invalid logType (value: ${logType})`\n );\n }\n};\n\nexport class Logger {\n /**\n * Gives you an instance of a Logger to capture messages according to\n * Firebase's logging scheme.\n *\n * @param name The name that the logs will be associated with\n */\n constructor(public name: string) {\n /**\n * Capture the current instance for later use\n */\n instances.push(this);\n }\n\n /**\n * The log level of the given Logger instance.\n */\n private _logLevel = defaultLogLevel;\n\n get logLevel(): LogLevel {\n return this._logLevel;\n }\n\n set logLevel(val: LogLevel) {\n if (!(val in LogLevel)) {\n throw new TypeError(`Invalid value \"${val}\" assigned to \\`logLevel\\``);\n }\n this._logLevel = val;\n }\n\n // Workaround for setter/getter having to be the same type.\n setLogLevel(val: LogLevel | LogLevelString): void {\n this._logLevel = typeof val === 'string' ? levelStringToEnum[val] : val;\n }\n\n /**\n * The main (internal) log handler for the Logger instance.\n * Can be set to a new function in internal package code but not by user.\n */\n private _logHandler: LogHandler = defaultLogHandler;\n get logHandler(): LogHandler {\n return this._logHandler;\n }\n set logHandler(val: LogHandler) {\n if (typeof val !== 'function') {\n throw new TypeError('Value assigned to `logHandler` must be a function');\n }\n this._logHandler = val;\n }\n\n /**\n * The optional, additional, user-defined log handler for the Logger instance.\n */\n private _userLogHandler: LogHandler | null = null;\n get userLogHandler(): LogHandler | null {\n return this._userLogHandler;\n }\n set userLogHandler(val: LogHandler | null) {\n this._userLogHandler = val;\n }\n\n /**\n * The functions below are all based on the `console` interface\n */\n\n debug(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.DEBUG, ...args);\n this._logHandler(this, LogLevel.DEBUG, ...args);\n }\n log(...args: unknown[]): void {\n this._userLogHandler &&\n this._userLogHandler(this, LogLevel.VERBOSE, ...args);\n this._logHandler(this, LogLevel.VERBOSE, ...args);\n }\n info(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.INFO, ...args);\n this._logHandler(this, LogLevel.INFO, ...args);\n }\n warn(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.WARN, ...args);\n this._logHandler(this, LogLevel.WARN, ...args);\n }\n error(...args: unknown[]): void {\n this._userLogHandler && this._userLogHandler(this, LogLevel.ERROR, ...args);\n this._logHandler(this, LogLevel.ERROR, ...args);\n }\n}\n\nexport function setLogLevel(level: LogLevelString | LogLevel): void {\n instances.forEach(inst => {\n inst.setLogLevel(level);\n });\n}\n\nexport function setUserLogHandler(\n logCallback: LogCallback | null,\n options?: LogOptions\n): void {\n for (const instance of instances) {\n let customLogLevel: LogLevel | null = null;\n if (options && options.level) {\n customLogLevel = levelStringToEnum[options.level];\n }\n if (logCallback === null) {\n instance.userLogHandler = null;\n } else {\n instance.userLogHandler = (\n instance: Logger,\n level: LogLevel,\n ...args: unknown[]\n ) => {\n const message = args\n .map(arg => {\n if (arg == null) {\n return null;\n } else if (typeof arg === 'string') {\n return arg;\n } else if (typeof arg === 'number' || typeof arg === 'boolean') {\n return arg.toString();\n } else if (arg instanceof Error) {\n return arg.message;\n } else {\n try {\n return JSON.stringify(arg);\n } catch (ignored) {\n return null;\n }\n }\n })\n .filter(arg => arg)\n .join(' ');\n if (level >= (customLogLevel ?? instance.logLevel)) {\n logCallback({\n level: LogLevel[level].toLowerCase() as LogLevelString,\n message,\n args,\n type: instance.name\n });\n }\n };\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;AAsCA;;;AAGO,IAAM,SAAS,GAAa,EAAE,CAAC;AAEtC;;;;;;;;;;;IAWY;AAAZ,WAAY,QAAQ;IAClB,yCAAK,CAAA;IACL,6CAAO,CAAA;IACP,uCAAI,CAAA;IACJ,uCAAI,CAAA;IACJ,yCAAK,CAAA;IACL,2CAAM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