Skip to content

Commit 7444b37

Browse files
committed
refactor(firestore-bigquery-export): code shortening
1 parent 1b920ee commit 7444b37

File tree

2 files changed

+18
-34
lines changed
  • firestore-bigquery-export

2 files changed

+18
-34
lines changed

firestore-bigquery-export/firestore-bigquery-change-tracker/src/logger.ts

+9-17
Original file line numberDiff line numberDiff line change
@@ -49,36 +49,28 @@ export class Logger {
4949
}
5050

5151
debug(...args: any[]): void {
52-
if (this.logLevel <= levels.debug) {
53-
funcsLogger.debug(...args);
54-
}
52+
this.runIfLogLevel(levels.debug, funcsLogger.debug, ...args);
5553
}
5654

5755
log(...args: any[]): void {
5856
this.info(...args);
5957
}
6058

6159
info(...args: any[]): void {
62-
if (
63-
this.logLevel <= levels.info
64-
) {
65-
funcsLogger.info(...args);
66-
}
60+
this.runIfLogLevel(levels.info, funcsLogger.info, ...args);
6761
}
6862

6963
warn(...args: any[]): void {
70-
if (
71-
this.logLevel <= levels.warn
72-
) {
73-
funcsLogger.warn(...args);
74-
}
64+
this.runIfLogLevel(levels.warn, funcsLogger.warn, ...args);
7565
}
7666

7767
error(...args: any[]): void {
78-
if (
79-
this.logLevel <= levels.error
80-
) {
81-
funcsLogger.error(...args);
68+
this.runIfLogLevel(levels.error, funcsLogger.error, ...args);
69+
}
70+
71+
private runIfLogLevel(level: number, func: Function, ...args: any[]): void {
72+
if (this.logLevel <= level) {
73+
func(...args);
8274
}
8375
}
8476
}

firestore-bigquery-export/functions/src/logger.ts

+9-17
Original file line numberDiff line numberDiff line change
@@ -49,36 +49,28 @@ export class Logger {
4949
}
5050

5151
debug(...args: any[]): void {
52-
if (this.logLevel <= levels.debug) {
53-
funcsLogger.debug(...args);
54-
}
52+
this.runIfLogLevel(levels.debug, funcsLogger.debug, ...args);
5553
}
5654

5755
log(...args: any[]): void {
5856
this.info(...args);
5957
}
6058

6159
info(...args: any[]): void {
62-
if (
63-
this.logLevel <= levels.info
64-
) {
65-
funcsLogger.info(...args);
66-
}
60+
this.runIfLogLevel(levels.info, funcsLogger.info, ...args);
6761
}
6862

6963
warn(...args: any[]): void {
70-
if (
71-
this.logLevel <= levels.warn
72-
) {
73-
funcsLogger.warn(...args);
74-
}
64+
this.runIfLogLevel(levels.warn, funcsLogger.warn, ...args);
7565
}
7666

7767
error(...args: any[]): void {
78-
if (
79-
this.logLevel <= levels.error
80-
) {
81-
funcsLogger.error(...args);
68+
this.runIfLogLevel(levels.error, funcsLogger.error, ...args);
69+
}
70+
71+
private runIfLogLevel(level: number, func: Function, ...args: any[]): void {
72+
if (this.logLevel <= level) {
73+
func(...args);
8274
}
8375
}
8476
}

0 commit comments

Comments
 (0)