@ayanaware/logger
Version:
Useful and great looking logging made easy
68 lines • 2.1 kB
JavaScript
;
// I know global should not be used but I have no idea how to make this stuff always work without it
// If you have a better solution please make a PR
Object.defineProperty(exports, "__esModule", { value: true });
exports.Config = void 0;
const DefaultFormatter_1 = require("../formatter/default/DefaultFormatter");
const ConsoleTransport_1 = require("../transports/ConsoleTransport");
/**
* @ignore
*/
const KEY = '__ayanaLogger__';
/**
* @ignore
*/
const VERSION = require('../../package.json').version;
/**
* @ignore
*/
const MAJOR = VERSION.split('.')[0];
/**
* This class is not package-safe!
* Do not use instanceof operations in here.
*
* @ignore
*/
class Config {
constructor() {
this.defaultTransport = new ConsoleTransport_1.ConsoleTransport();
this.formatter = new DefaultFormatter_1.DefaultFormatter();
this.transports = [];
this.globalExtra = {};
Object.defineProperty(this, 'version', {
configurable: false,
writable: false,
enumerable: true,
value: VERSION,
});
Object.defineProperty(this, 'major', {
configurable: false,
writable: false,
enumerable: true,
value: MAJOR,
});
this.transports.push(this.defaultTransport);
}
disableDefaultTransport() {
if (this.defaultTransport == null)
return;
this.transports.splice(0, 1);
this.defaultTransport = null;
}
static getInstance() {
if (!global[KEY] || typeof global[KEY] !== 'object') {
global[KEY] = Object.create(null);
}
if (!global[KEY][MAJOR] || typeof global[KEY][MAJOR] !== 'object') {
global[KEY][MAJOR] = new Config();
}
const config = global[KEY][MAJOR];
// We need to add the globalExtra object to a config created by V2.0 or V2.1
if (config.globalExtra == null) {
config.globalExtra = {};
}
return config;
}
}
exports.Config = Config;
//# sourceMappingURL=Config.js.map