ngx-restful-client
Version:
The ultimate Angular library to exquisitely declare and implement the REST APIs you'll use in your application.
91 lines (90 loc) • 3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Initial configuration of logger methods ...
* Will print a message alerting of configuration needs
*
* @param data
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var configureEmpty = function () {
var data = [];
for (var _i = 0; _i < arguments.length; _i++) {
data[_i] = arguments[_i];
}
console.log('You should configure Logger at the first code line in your application bootstrap ' +
'JS or TS file calling LoggerConfig.configure(env.production);');
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var empty = function () {
var data = [];
for (var _i = 0; _i < arguments.length; _i++) {
data[_i] = arguments[_i];
}
return;
};
var Logger = /** @class */ (function () {
function Logger() {
}
Logger.trace = configureEmpty;
Logger.debug = configureEmpty;
Logger.info = configureEmpty;
Logger.warn = configureEmpty;
Logger.error = configureEmpty;
return Logger;
}());
/**
* Provê uma forma simples e configurável para adicionar logs na aplicação sem que seja preciso removê-los depois.
* Utilizando esse recurso basta que a chamada LoggerConfig.configure(isProduction()) para que os logs de nível DEBUG e
* INFO estejam habilitados apenas em desenvolvimento - localhost - ou produção, por ex.
*
*/
exports.logger = Logger;
/**
* Recomenda-se configurar o logger antes da aplicação ser inicializada em seu bootstrap() no
* arquivo <strong>main.ts</strong>, ou no momento em que a aplicação já reconheça qual ambiente esteja implantada.
*
* Caso a configuração não seja feita, o único método disponível para uso será o info.
*
*/
var LoggerConfig = /** @class */ (function () {
function LoggerConfig() {
}
LoggerConfig.configure = function (production) {
this.emptyLogger();
var lvl = Level.TRACE;
if (production) {
lvl = Level.WARN;
}
switch (lvl) {
case Level.TRACE:
Logger.trace = console.trace;
Logger.debug = console.debug;
Logger.info = console.info;
case Level.WARN:
Logger.warn = console.warn;
Logger.error = console.error;
break;
default:
Logger.info = console.info;
}
Object.freeze(Logger);
};
LoggerConfig.emptyLogger = function () {
Logger.trace = empty;
Logger.debug = empty;
Logger.info = empty;
Logger.warn = empty;
Logger.error = empty;
};
return LoggerConfig;
}());
exports.LoggerConfig = LoggerConfig;
var Level;
(function (Level) {
Level[Level["TRACE"] = 0] = "TRACE";
Level[Level["DEBUG"] = 1] = "DEBUG";
Level[Level["INFO"] = 2] = "INFO";
Level[Level["WARN"] = 3] = "WARN";
Level[Level["ERROR"] = 4] = "ERROR";
})(Level || (Level = {}));