@villedemontreal/http-request
Version:
HTTP utilities - send HTTP requests with proper headers, etc.
53 lines • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createLogger = createLogger;
exports.getTestingLoggerCreator = getTestingLoggerCreator;
const logger_1 = require("@villedemontreal/logger");
const configs_1 = require("../config/configs");
let testingLoggerLibInitialised = false;
/**
* Creates a Logger.
*/
function createLogger(name) {
// ==========================================
// We use a LazyLogger so the real Logger
// is only created when the first
// log is actually performed... At that point,
// our "configs.loggerCreator" configuration
// must have been set by the code using our library!
//
// This pattern allows calling code to import
// modules from us in which a logger is
// created in the global scope :
//
// let logger = createLogger('someName');
//
// Without a Lazy Logger, the library configurations
// would at that moment *not* have been set yet
// (by the calling code) and an Error would be thrown
// because the "configs.loggerCreator" is required.
// ==========================================
return new logger_1.LazyLogger(name, (nameArg) => {
return configs_1.configs.loggerCreator(nameArg);
});
}
function initTestingLoggerConfigs() {
const loggerConfig = new logger_1.LoggerConfigs(() => 'test-cid');
loggerConfig.setLogLevel(logger_1.LogLevel.DEBUG);
(0, logger_1.initLogger)(loggerConfig);
}
/**
* A Logger that uses a dummy cid provider.
*
* Only use this when running the tests!
*/
function getTestingLoggerCreator() {
return (name) => {
if (!testingLoggerLibInitialised) {
initTestingLoggerConfigs();
testingLoggerLibInitialised = true;
}
return new logger_1.Logger(name);
};
}
//# sourceMappingURL=logger.js.map