"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeviceLogEmitter = void 0;
const device_log_provider_base_1 = require("./device-log-provider-base");
const constants_1 = require("../constants");
const yok_1 = require("../yok");
const _ = require("lodash");
class DeviceLogEmitter extends device_log_provider_base_1.DeviceLogProviderBase {
    constructor($logFilter, $logger, $loggingLevels, $logSourceMapService) {
        super($logFilter, $logger, $logSourceMapService);
        this.$logFilter = $logFilter;
        this.$loggingLevels = $loggingLevels;
        this.$logSourceMapService = $logSourceMapService;
    }
    logData(line, platform, deviceIdentifier) {
        this.setDefaultLogLevelForDevice(deviceIdentifier);
        const loggingOptions = this.getDeviceLogOptionsForDevice(deviceIdentifier) || { logLevel: this.$loggingLevels.info, projectDir: null };
        let data = this.$logFilter.filterData(platform, line, loggingOptions);
        data = this.$logSourceMapService.replaceWithOriginalFileLocations(platform, data, loggingOptions);
        if (data) {
            this.emit("data", deviceIdentifier, data);
            this.emit(constants_1.DEVICE_LOG_EVENT_NAME, data, deviceIdentifier, platform);
        }
    }
    setLogLevel(logLevel, deviceIdentifier) {
        if (deviceIdentifier) {
            this.setDeviceLogOptionsProperty(deviceIdentifier, (deviceLogOptions) => deviceLogOptions.logLevel, logLevel.toUpperCase());
        }
        else {
            this.$logFilter.loggingLevel = logLevel.toUpperCase();
            _.keys(this.devicesLogOptions).forEach((deviceId) => {
                this.devicesLogOptions[deviceId] =
                    this.devicesLogOptions[deviceId] || {};
                this.devicesLogOptions[deviceId].logLevel = this.$logFilter.loggingLevel;
            });
        }
    }
}
exports.DeviceLogEmitter = DeviceLogEmitter;
yok_1.injector.register("deviceLogProvider", DeviceLogEmitter);
//# sourceMappingURL=device-log-emitter.js.map