mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
fix(webpack): added loading of core appenders
This commit is contained in:
parent
8f7fde9da0
commit
11b21ce773
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user