-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlog-filter.ts
69 lines (60 loc) · 1.87 KB
/
log-filter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { IInjector } from "../definitions/yok";
import { injector } from "../yok";
export class LogFilter implements Mobile.ILogFilter {
private _loggingLevel: string = this.$loggingLevels.info;
constructor(
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $injector: IInjector,
private $loggingLevels: Mobile.ILoggingLevels
) {}
public get loggingLevel(): string {
return this._loggingLevel;
}
public set loggingLevel(logLevel: string) {
if (this.verifyLogLevel(logLevel)) {
this._loggingLevel = logLevel;
}
}
public filterData(
platform: string,
data: string,
loggingOptions: Mobile.IDeviceLogOptions = <any>{}
): string {
loggingOptions = loggingOptions || <any>{};
const deviceLogFilter = this.getDeviceLogFilterInstance(platform);
loggingOptions.logLevel = loggingOptions.logLevel || this.loggingLevel;
if (deviceLogFilter) {
return deviceLogFilter.filterData(data, loggingOptions);
}
// In case the platform is not valid, just return the data without filtering.
return data;
}
private getDeviceLogFilterInstance(
platform: string
): Mobile.IPlatformLogFilter {
if (platform) {
if (
platform.toLowerCase() ===
this.$devicePlatformsConstants.iOS.toLowerCase() ||
platform.toLowerCase() ===
this.$devicePlatformsConstants.visionOS.toLowerCase()
) {
return this.$injector.resolve("iOSLogFilter");
} else if (
platform.toLowerCase() ===
this.$devicePlatformsConstants.Android.toLowerCase()
) {
return this.$injector.resolve("androidLogFilter");
}
}
return null;
}
private verifyLogLevel(logLevel: string): boolean {
const upperCaseLogLevel = (logLevel || "").toUpperCase();
return (
upperCaseLogLevel === this.$loggingLevels.info.toUpperCase() ||
upperCaseLogLevel === this.$loggingLevels.full.toUpperCase()
);
}
}
injector.register("logFilter", LogFilter);