|
19 | 19 | import { SDK_VERSION } from '../core/version';
|
20 | 20 | import { AnyJs } from './misc';
|
21 | 21 | import { PlatformSupport } from '../platform/platform';
|
| 22 | +import { Logger, LogLevel as _LogLevel } from "@firebase/logger"; |
| 23 | + |
| 24 | +const client = new Logger(); |
22 | 25 |
|
23 | 26 | export enum LogLevel {
|
24 | 27 | DEBUG,
|
25 | 28 | ERROR,
|
26 | 29 | SILENT
|
27 | 30 | }
|
28 | 31 |
|
29 |
| -let logLevel = LogLevel.ERROR; |
30 |
| - |
31 | 32 | // Helper methods are needed because variables can't be exported as read/write
|
32 | 33 | export function getLogLevel(): LogLevel {
|
33 |
| - return logLevel; |
| 34 | + if (client.logLevel === _LogLevel.DEBUG) { |
| 35 | + return LogLevel.DEBUG; |
| 36 | + } |
| 37 | + |
| 38 | + if (client.logLevel === _LogLevel.SILENT) { |
| 39 | + return LogLevel.SILENT; |
| 40 | + } |
| 41 | + |
| 42 | + return LogLevel.ERROR; |
34 | 43 | }
|
35 | 44 | export function setLogLevel(newLevel: LogLevel): void {
|
36 |
| - logLevel = newLevel; |
| 45 | + client.logLevel = newLevel; |
37 | 46 | }
|
38 | 47 |
|
39 | 48 | export function debug(tag: string, msg: string, ...obj: AnyJs[]): void {
|
40 |
| - if (logLevel <= LogLevel.DEBUG) { |
41 |
| - const time = new Date().toISOString(); |
42 |
| - const args = obj.map(argToString); |
43 |
| - console.log(`Firestore (${SDK_VERSION}) ${time} [${tag}]: ${msg}`, ...args); |
44 |
| - } |
| 49 | + const time = new Date().toISOString(); |
| 50 | + const args = obj.map(argToString); |
| 51 | + client.log(`Firestore (${SDK_VERSION}) ${time} [${tag}]: ${msg}`, ...args); |
45 | 52 | }
|
46 | 53 |
|
47 | 54 | export function error(msg: string, ...obj: AnyJs[]): void {
|
48 |
| - if (logLevel <= LogLevel.ERROR) { |
49 |
| - const time = new Date().toISOString(); |
50 |
| - const args = obj.map(argToString); |
51 |
| - console.error(`Firestore (${SDK_VERSION}) ${time}: ${msg}`, ...args); |
52 |
| - } |
| 55 | + const time = new Date().toISOString(); |
| 56 | + const args = obj.map(argToString); |
| 57 | + client.error(`Firestore (${SDK_VERSION}) ${time}: ${msg}`, ...args); |
53 | 58 | }
|
54 | 59 |
|
55 | 60 | /**
|
|
0 commit comments