|
| 1 | +///<reference path="../.d.ts"/> |
| 2 | +"use strict"; |
| 3 | + |
| 4 | +export class LogFilter implements Mobile.ILogFilter { |
| 5 | + private _loggingLevel: string = this.$loggingLevels.info; |
| 6 | + |
| 7 | + constructor(private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, |
| 8 | + private $injector: IInjector, |
| 9 | + private $loggingLevels: Mobile.ILoggingLevels) {} |
| 10 | + |
| 11 | + public get loggingLevel(): string { |
| 12 | + return this._loggingLevel; |
| 13 | + } |
| 14 | + |
| 15 | + public set loggingLevel(logLevel: string) { |
| 16 | + if(this.verifyLogLevel(logLevel)) { |
| 17 | + this._loggingLevel = logLevel; |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + public filterData(platform: string, data: string, logLevel?: string): string { |
| 22 | + let deviceLogFilter = this.getDeviceLogFilterInstance(platform); |
| 23 | + if(deviceLogFilter) { |
| 24 | + return deviceLogFilter.filterData(data, logLevel || this.loggingLevel); |
| 25 | + } |
| 26 | + |
| 27 | + // In case the platform is not valid, just return the data without filtering. |
| 28 | + return data; |
| 29 | + } |
| 30 | + |
| 31 | + private getDeviceLogFilterInstance(platform: string): Mobile.IPlatformLogFilter { |
| 32 | + if(platform) { |
| 33 | + if(platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) { |
| 34 | + return this.$injector.resolve("iOSLogFilter"); |
| 35 | + } else if(platform.toLowerCase() === this.$devicePlatformsConstants.Android.toLowerCase()) { |
| 36 | + return this.$injector.resolve("androidLogFilter"); |
| 37 | + } |
| 38 | + } |
| 39 | + return null; |
| 40 | + } |
| 41 | + |
| 42 | + private verifyLogLevel(logLevel: string): boolean { |
| 43 | + let upperCaseLogLevel = (logLevel || '').toUpperCase(); |
| 44 | + return upperCaseLogLevel === this.$loggingLevels.info.toUpperCase() || upperCaseLogLevel === this.$loggingLevels.full.toUpperCase(); |
| 45 | + } |
| 46 | + |
| 47 | +} |
| 48 | +$injector.register("logFilter", LogFilter); |
0 commit comments