import { Injectable } from '@angular/core'; import { AppConf } from '../app-conf/app-conf'; import { AppUtil } from '../app-util/app-util'; // $filelogger @Injectable() export class ConsoleSevice { LoggerLevels = { INFO: 'info', ERROR: 'error', WARN: 'warn', DEBUG: 'debug', LOG: 'log' }; constructor(public appConf: AppConf, public appUtil: AppUtil, ) { } FileLoggerFilter(description, object, typelog) { if (this.appConf.getTheLoggerLevel() == "ALL") { if (typelog == this.LoggerLevels.ERROR || typelog == this.LoggerLevels.INFO || typelog == this.LoggerLevels.WARN || typelog == this.LoggerLevels.INFO) { return this.generateLog(object, typelog, description); } } else if (this.appConf.getTheLoggerLevel() == "INFO") { if (typelog == this.LoggerLevels.ERROR || typelog == this.LoggerLevels.INFO || typelog == this.LoggerLevels.WARN) { return this.generateLog(object, typelog, description); } } else if (this.appConf.getTheLoggerLevel() == "WARN") { if (typelog == this.LoggerLevels.ERROR || typelog == this.LoggerLevels.WARN) { return this.generateLog(object, typelog, description); } } else if (this.appConf.getTheLoggerLevel() == "ERROR") { if (typelog == this.LoggerLevels.ERROR) { return this.generateLog(object, typelog, description); } } else if (this.appConf.getTheLoggerLevel() == "OFF") { // NOTHING HERE... } } generateLog(object, typelog, description) { if (object) { // $fileLogger.log(typelog, description + JSON.stringify(object)); return description + JSON.stringify(object); } else { // $fileLogger.log(typelog, description); return description; } } Error(err, object, isalert) { this.appUtil.hideLoading(); if (isalert === true) { this.appUtil.alert(err + JSON.stringify(object), ''); } return this.FileLoggerFilter(err, object, this.LoggerLevels.ERROR); }; Info(info, object, isalert) { if (isalert === true) { this.appUtil.alert(info + JSON.stringify(object),''); } return this.FileLoggerFilter(info, object, this.LoggerLevels.INFO); }; Warn(warn, object, isalert) { this.appUtil.hideLoading(); if (isalert === true) { this.appUtil.alert(warn + JSON.stringify(object),''); } return this.FileLoggerFilter(warn, object, this.LoggerLevels.WARN); }; }