Skip to content

Commit 4e59a63

Browse files
committed
Do @firebase/firestore integration
1 parent 293e6d8 commit 4e59a63

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

packages/firestore/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"license": "Apache-2.0",
2323
"dependencies": {
2424
"@firebase/firestore-types": "0.2.1",
25+
"@firebase/logger": "0.1.0",
2526
"@firebase/webchannel-wrapper": "0.2.6",
2627
"grpc": "^1.7.1"
2728
},

packages/firestore/src/util/log.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,42 @@
1919
import { SDK_VERSION } from '../core/version';
2020
import { AnyJs } from './misc';
2121
import { PlatformSupport } from '../platform/platform';
22+
import { Logger, LogLevel as _LogLevel } from "@firebase/logger";
23+
24+
const client = new Logger();
2225

2326
export enum LogLevel {
2427
DEBUG,
2528
ERROR,
2629
SILENT
2730
}
2831

29-
let logLevel = LogLevel.ERROR;
30-
3132
// Helper methods are needed because variables can't be exported as read/write
3233
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;
3443
}
3544
export function setLogLevel(newLevel: LogLevel): void {
36-
logLevel = newLevel;
45+
client.logLevel = newLevel;
3746
}
3847

3948
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);
4552
}
4653

4754
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);
5358
}
5459

5560
/**

0 commit comments

Comments
 (0)