-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathdevice-log-provider-base.ts
54 lines (41 loc) · 2.33 KB
/
device-log-provider-base.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
import { EventEmitter } from "events";
import { getPropertyName } from "../helpers";
export abstract class DeviceLogProviderBase extends EventEmitter implements Mobile.IDeviceLogProvider {
protected devicesLogOptions: IDictionary<Mobile.IDeviceLogOptions> = {};
constructor(protected $logFilter: Mobile.ILogFilter,
protected $logger: ILogger) {
super();
}
public abstract logData(lineText: string, platform: string, deviceIdentifier: string): void;
public abstract setLogLevel(logLevel: string, deviceIdentifier?: string): void;
public setApplicationPidForDevice(deviceIdentifier: string, pid: string): void {
this.setDeviceLogOptionsProperty(deviceIdentifier, (deviceLogOptions: Mobile.IDeviceLogOptions) => deviceLogOptions.applicationPid, pid);
}
public setProjectNameForDevice(deviceIdentifier: string, projectName: string): void {
this.setDeviceLogOptionsProperty(deviceIdentifier, (deviceLogOptions: Mobile.IDeviceLogOptions) => deviceLogOptions.projectName, projectName);
}
protected setDefaultLogLevelForDevice(deviceIdentifier: string): void {
const logLevel = (this.devicesLogOptions[deviceIdentifier] && this.devicesLogOptions[deviceIdentifier].logLevel) || this.$logFilter.loggingLevel;
this.setLogLevel(logLevel, deviceIdentifier);
}
public muteLogsForDevice(deviceIdentifier: string): void {
this.setDeviceLogOptionsProperty(deviceIdentifier, (deviceLogOptions: Mobile.IDeviceLogOptions) => deviceLogOptions.muteLogs, true);
}
protected getApplicationPidForDevice(deviceIdentifier: string): string {
return this.devicesLogOptions[deviceIdentifier] && this.devicesLogOptions[deviceIdentifier].applicationPid;
}
protected getDeviceLogOptionsForDevice(deviceIdentifier: string): Mobile.IDeviceLogOptions {
const loggingOptions = this.devicesLogOptions[deviceIdentifier];
if (!loggingOptions) {
this.setDefaultLogLevelForDevice(deviceIdentifier);
}
return this.devicesLogOptions[deviceIdentifier];
}
protected setDeviceLogOptionsProperty(deviceIdentifier: string, propNameFunction: Function, propertyValue: string | boolean): void {
const propertyName = getPropertyName(propNameFunction);
if (propertyName) {
this.devicesLogOptions[deviceIdentifier] = this.devicesLogOptions[deviceIdentifier] || <Mobile.IDeviceLogOptions>{};
this.devicesLogOptions[deviceIdentifier][propertyName] = propertyValue;
}
}
}