Skip to content
Permalink
Browse files

fix(webpack): added loading of core appenders

  • Loading branch information
Gareth Jones
Gareth Jones committed Jan 31, 2018
1 parent 8f7fde9 commit 11b21ce77360ae7e730d0bb173f186d04f2760ec
Showing with 30 additions and 26 deletions.
  1. +13 −10 lib/appenders/index.js
  2. +0 −3 lib/categories.js
  3. +17 −13 lib/log4js.js
@@ -5,6 +5,14 @@ const clustering = require('../clustering');
const levels = require('../levels');
const layouts = require('../layouts');

// pre-load the core appenders so that webpack can find them
const coreAppenders = new Map();
coreAppenders.set('console', require('./console'));
coreAppenders.set('stdout', require('./stdout'));
coreAppenders.set('stderr', require('./stderr'));
coreAppenders.set('file', require('./file'));
coreAppenders.set('dateFile', require('./dateFile'));

const appenders = new Map();

const tryLoading = (modulePath, config) => {
@@ -22,10 +30,11 @@ const tryLoading = (modulePath, config) => {
}
};

const loadAppenderModule = (type, config) => tryLoading(`./${type}`, config) ||
tryLoading(type, config) ||
tryLoading(path.join(path.dirname(require.main.filename), type), config) ||
tryLoading(path.join(process.cwd(), type), config);
const loadAppenderModule = (type, config) => coreAppenders.get(type) ||
tryLoading(`./${type}`, config) ||
tryLoading(type, config) ||
tryLoading(path.join(path.dirname(require.main.filename), type), config) ||
tryLoading(path.join(process.cwd(), type), config);

const createAppender = (name, config) => {
const appenderConfig = config.appenders[name];
@@ -64,12 +73,6 @@ const setup = (config) => {
});
};

// setup({
// appenders: {
// stdout: { type: 'stdout' }
// }
// });

configuration.addListener((config) => {
configuration.throwExceptionIf(
config,
@@ -83,9 +83,6 @@ const setup = (config) => {
});
};

// setup({
// categories: { default: { appenders: ['stdout'], level: 'OFF' } }
// });
configuration.addListener(setup);

const configForCategory = (category) => {
@@ -42,19 +42,6 @@ function sendLogEventToAppender(logEvent) {
});
}

/**
* Get a logger instance.
* @static
* @param loggerCategoryName
* @return {Logger} instance of logger for the category
*/
function getLogger(category) {
if (!enabled) {
configure(process.env.LOG4JS_CONFIG || defaultConfig);
}
return new Logger(category || 'default');
}

function loadConfigurationFile(filename) {
if (filename) {
debug(`Loading configuration from ${filename}`);
@@ -118,6 +105,23 @@ function shutdown(cb) {
return null;
}

/**
* Get a logger instance.
* @static
* @param loggerCategoryName
* @return {Logger} instance of logger for the category
*/
function getLogger(category) {
if (!enabled) {
configure(process.env.LOG4JS_CONFIG || {
appenders: { out: { type: 'stdout' } },
categories: { default: { appenders: ['out'], level: 'OFF' } }
});
}
return new Logger(category || 'default');
}


/**
* @name log4js
* @namespace Log4js

0 comments on commit 11b21ce

Please sign in to comment.
You can’t perform that action at this time.