Skip to content

Commit 4f4ed0a

Browse files
authored
Add support to inject BI logger to our LogService (#2434)
* Add support to inject BI logger to our LogService * Minor changes in LogService
1 parent bb29491 commit 4f4ed0a

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

src/services/LogService.ts

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
1-
function warn(message: string) {
2-
if (__DEV__) {
3-
console.warn(message);
4-
}
1+
interface BILogger {
2+
log: (event: any) => void;
53
}
4+
class LogService {
5+
private biLogger: BILogger | undefined;
6+
7+
injectBILogger = (biLogger: BILogger) => {
8+
this.biLogger = biLogger;
9+
};
610

7-
function error(message: string) {
8-
if (__DEV__) {
9-
console.error(message);
11+
logBI = (event: any) => {
12+
this.biLogger?.log(event);
1013
}
14+
15+
warn = (message: string) => {
16+
if (__DEV__) {
17+
console.warn(message);
18+
}
19+
};
20+
21+
error = (message: string) => {
22+
if (__DEV__) {
23+
console.error(message);
24+
}
25+
};
26+
27+
deprecationWarn = ({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) => {
28+
this.warn(getDeprecationMessage({component, oldProp, newProp}));
29+
};
30+
31+
componentDeprecationWarn = ({oldComponent, newComponent}: {oldComponent: string; newComponent: string}) => {
32+
this.warn(getComponentDeprecationMessage({oldComponent, newComponent}));
33+
};
34+
35+
deprecationError = ({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) => {
36+
this.error(getDeprecationMessage({component, oldProp, newProp}));
37+
};
38+
39+
componentDeprecationError = ({oldComponent, newComponent}: {oldComponent: string; newComponent: string}) => {
40+
this.error(getComponentDeprecationMessage({oldComponent, newComponent}));
41+
};
1142
}
1243

1344
function getDeprecationMessage({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) {
@@ -23,27 +54,4 @@ function getComponentDeprecationMessage({oldComponent, newComponent}: {oldCompon
2354
return message;
2455
}
2556

26-
function deprecationWarn({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) {
27-
warn(getDeprecationMessage({component, oldProp, newProp}));
28-
}
29-
30-
function componentDeprecationWarn({oldComponent, newComponent}: {oldComponent: string; newComponent: string}) {
31-
warn(getComponentDeprecationMessage({oldComponent, newComponent}));
32-
}
33-
34-
function deprecationError({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) {
35-
error(getDeprecationMessage({component, oldProp, newProp}));
36-
}
37-
38-
function componentDeprecationError({oldComponent, newComponent}: {oldComponent: string; newComponent: string}) {
39-
error(getComponentDeprecationMessage({oldComponent, newComponent}));
40-
}
41-
42-
export default {
43-
warn,
44-
error,
45-
deprecationWarn,
46-
componentDeprecationWarn,
47-
deprecationError,
48-
componentDeprecationError
49-
};
57+
export default new LogService();

0 commit comments

Comments
 (0)