UNPKG

@log4js-node/log4js-api

Version:

For libraries that want to include log4js for logging, but don't want to introduce version conflicts for users that also use log4js. Delegates to whatever log4js version can be found, but does not introduce a specific log4js version.

36 lines (25 loc) 587 B
class Logger { log() {} isLevelEnabled() { return false; } addContext() {} removeContext() {} clearContext() {} } [ 'Trace', 'Debug', 'Info', 'Warn', 'Error', 'Fatal', 'Mark' ].forEach((level) => { Logger.prototype[level.toLowerCase()] = () => {}; Logger.prototype[`is${level}Enabled`] = () => false; }); const checkForLog4js = () => { try { return require('log4js'); } catch (e) { return null; } }; const log4js = checkForLog4js(); const loggerFn = log4js ? log4js.getLogger : () => new Logger(); module.exports = { getLogger: loggerFn };