UNPKG

3.39 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17export declare type LogLevelString = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'silent';
18export interface LogOptions {
19 level: LogLevelString;
20}
21export declare type LogCallback = (callbackParams: LogCallbackParams) => void;
22export interface LogCallbackParams {
23 level: LogLevelString;
24 message: string;
25 args: unknown[];
26 type: string;
27}
28/**
29 * A container for all of the Logger instances
30 */
31export declare const instances: Logger[];
32/**
33 * The JS SDK supports 5 log levels and also allows a user the ability to
34 * silence the logs altogether.
35 *
36 * The order is a follows:
37 * DEBUG < VERBOSE < INFO < WARN < ERROR
38 *
39 * All of the log types above the current log level will be captured (i.e. if
40 * you set the log level to `INFO`, errors will still be logged, but `DEBUG` and
41 * `VERBOSE` logs will not)
42 */
43export declare enum LogLevel {
44 DEBUG = 0,
45 VERBOSE = 1,
46 INFO = 2,
47 WARN = 3,
48 ERROR = 4,
49 SILENT = 5
50}
51/**
52 * We allow users the ability to pass their own log handler. We will pass the
53 * type of log, the current log level, and any other arguments passed (i.e. the
54 * messages that the user wants to log) to this function.
55 */
56export declare type LogHandler = (loggerInstance: Logger, logType: LogLevel, ...args: unknown[]) => void;
57export declare class Logger {
58 name: string;
59 /**
60 * Gives you an instance of a Logger to capture messages according to
61 * Firebase's logging scheme.
62 *
63 * @param name The name that the logs will be associated with
64 */
65 constructor(name: string);
66 /**
67 * The log level of the given Logger instance.
68 */
69 private _logLevel;
70 get logLevel(): LogLevel;
71 set logLevel(val: LogLevel);
72 setLogLevel(val: LogLevel | LogLevelString): void;
73 /**
74 * The main (internal) log handler for the Logger instance.
75 * Can be set to a new function in internal package code but not by user.
76 */
77 private _logHandler;
78 get logHandler(): LogHandler;
79 set logHandler(val: LogHandler);
80 /**
81 * The optional, additional, user-defined log handler for the Logger instance.
82 */
83 private _userLogHandler;
84 get userLogHandler(): LogHandler | null;
85 set userLogHandler(val: LogHandler | null);
86 /**
87 * The functions below are all based on the `console` interface
88 */
89 debug(...args: unknown[]): void;
90 log(...args: unknown[]): void;
91 info(...args: unknown[]): void;
92 warn(...args: unknown[]): void;
93 error(...args: unknown[]): void;
94}
95export declare function setLogLevel(level: LogLevelString | LogLevel): void;
96export declare function setUserLogHandler(logCallback: LogCallback | null, options?: LogOptions): void;