first commit

This commit is contained in:
2024-01-19 11:09:11 +01:00
commit b18af7a943
29473 changed files with 4500547 additions and 0 deletions

46
node_modules/log4js/lib/appenders/adapters.js generated vendored Normal file
View File

@@ -0,0 +1,46 @@
function maxFileSizeUnitTransform(maxLogSize) {
if (typeof maxLogSize === 'number' && Number.isInteger(maxLogSize)) {
return maxLogSize;
}
const units = {
K: 1024,
M: 1024 * 1024,
G: 1024 * 1024 * 1024,
};
const validUnit = Object.keys(units);
const unit = maxLogSize.slice(-1).toLocaleUpperCase();
const value = maxLogSize.slice(0, -1).trim();
if (validUnit.indexOf(unit) < 0 || !Number.isInteger(Number(value))) {
throw Error(`maxLogSize: "${maxLogSize}" is invalid`);
} else {
return value * units[unit];
}
}
function adapter(configAdapter, config) {
const newConfig = Object.assign({}, config); // eslint-disable-line prefer-object-spread
Object.keys(configAdapter).forEach((key) => {
if (newConfig[key]) {
newConfig[key] = configAdapter[key](config[key]);
}
});
return newConfig;
}
function fileAppenderAdapter(config) {
const configAdapter = {
maxLogSize: maxFileSizeUnitTransform,
};
return adapter(configAdapter, config);
}
const adapters = {
dateFile: fileAppenderAdapter,
file: fileAppenderAdapter,
fileSync: fileAppenderAdapter,
};
module.exports.modifyConfig = (config) =>
adapters[config.type] ? adapters[config.type](config) : config;

19
node_modules/log4js/lib/appenders/categoryFilter.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
const debug = require('debug')('log4js:categoryFilter');
function categoryFilter(excludes, appender) {
if (typeof excludes === 'string') excludes = [excludes];
return (logEvent) => {
debug(`Checking ${logEvent.categoryName} against ${excludes}`);
if (excludes.indexOf(logEvent.categoryName) === -1) {
debug('Not excluded, sending to appender');
appender(logEvent);
}
};
}
function configure(config, layouts, findAppender) {
const appender = findAppender(config.appender);
return categoryFilter(config.exclude, appender);
}
module.exports.configure = configure;

18
node_modules/log4js/lib/appenders/console.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
// eslint-disable-next-line no-console
const consoleLog = console.log.bind(console);
function consoleAppender(layout, timezoneOffset) {
return (loggingEvent) => {
consoleLog(layout(loggingEvent, timezoneOffset));
};
}
function configure(config, layouts) {
let layout = layouts.colouredLayout;
if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
return consoleAppender(layout, config.timezoneOffset);
}
module.exports.configure = configure;

76
node_modules/log4js/lib/appenders/dateFile.js generated vendored Normal file
View File

@@ -0,0 +1,76 @@
const streams = require('streamroller');
const os = require('os');
const eol = os.EOL;
function openTheStream(filename, pattern, options) {
const stream = new streams.DateRollingFileStream(filename, pattern, options);
stream.on('error', (err) => {
// eslint-disable-next-line no-console
console.error(
'log4js.dateFileAppender - Writing to file %s, error happened ',
filename,
err
);
});
stream.on('drain', () => {
process.emit('log4js:pause', false);
});
return stream;
}
/**
* File appender that rolls files according to a date pattern.
* @param filename base filename.
* @param pattern the format that will be added to the end of filename when rolling,
* also used to check when to roll files - defaults to '.yyyy-MM-dd'
* @param layout layout function for log messages - defaults to basicLayout
* @param options - options to be passed to the underlying stream
* @param timezoneOffset - optional timezone offset in minutes (default system local)
*/
function appender(filename, pattern, layout, options, timezoneOffset) {
// the options for file appender use maxLogSize, but the docs say any file appender
// options should work for dateFile as well.
options.maxSize = options.maxLogSize;
const writer = openTheStream(filename, pattern, options);
const app = function (logEvent) {
if (!writer.writable) {
return;
}
if (!writer.write(layout(logEvent, timezoneOffset) + eol, 'utf8')) {
process.emit('log4js:pause', true);
}
};
app.shutdown = function (complete) {
writer.end('', 'utf-8', complete);
};
return app;
}
function configure(config, layouts) {
let layout = layouts.basicLayout;
if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
if (!config.alwaysIncludePattern) {
config.alwaysIncludePattern = false;
}
// security default (instead of relying on streamroller default)
config.mode = config.mode || 0o600;
return appender(
config.filename,
config.pattern,
layout,
config,
config.timezoneOffset
);
}
module.exports.configure = configure;

154
node_modules/log4js/lib/appenders/file.js generated vendored Normal file
View File

@@ -0,0 +1,154 @@
const debug = require('debug')('log4js:file');
const path = require('path');
const streams = require('streamroller');
const os = require('os');
const eol = os.EOL;
let mainSighupListenerStarted = false;
const sighupListeners = new Set();
function mainSighupHandler() {
sighupListeners.forEach((app) => {
app.sighupHandler();
});
}
/**
* File Appender writing the logs to a text file. Supports rolling of logs by size.
*
* @param file the file log messages will be written to
* @param layout a function that takes a logEvent and returns a string
* (defaults to basicLayout).
* @param logSize - the maximum size (in bytes) for a log file,
* if not provided then logs won't be rotated.
* @param numBackups - the number of log files to keep after logSize
* has been reached (default 5)
* @param options - options to be passed to the underlying stream
* @param timezoneOffset - optional timezone offset in minutes (default system local)
*/
function fileAppender(
file,
layout,
logSize,
numBackups,
options,
timezoneOffset
) {
if (typeof file !== 'string' || file.length === 0) {
throw new Error(`Invalid filename: ${file}`);
} else if (file.endsWith(path.sep)) {
throw new Error(`Filename is a directory: ${file}`);
} else if (file.indexOf(`~${path.sep}`) === 0) {
// handle ~ expansion: https://github.com/nodejs/node/issues/684
// exclude ~ and ~filename as these can be valid files
file = file.replace('~', os.homedir());
}
file = path.normalize(file);
numBackups = !numBackups && numBackups !== 0 ? 5 : numBackups;
debug(
'Creating file appender (',
file,
', ',
logSize,
', ',
numBackups,
', ',
options,
', ',
timezoneOffset,
')'
);
function openTheStream(filePath, fileSize, numFiles, opt) {
const stream = new streams.RollingFileStream(
filePath,
fileSize,
numFiles,
opt
);
stream.on('error', (err) => {
// eslint-disable-next-line no-console
console.error(
'log4js.fileAppender - Writing to file %s, error happened ',
filePath,
err
);
});
stream.on('drain', () => {
process.emit('log4js:pause', false);
});
return stream;
}
let writer = openTheStream(file, logSize, numBackups, options);
const app = function (loggingEvent) {
if (!writer.writable) {
return;
}
if (options.removeColor === true) {
// eslint-disable-next-line no-control-regex
const regex = /\x1b[[0-9;]*m/g;
loggingEvent.data = loggingEvent.data.map((d) => {
if (typeof d === 'string') return d.replace(regex, '');
return d;
});
}
if (!writer.write(layout(loggingEvent, timezoneOffset) + eol, 'utf8')) {
process.emit('log4js:pause', true);
}
};
app.reopen = function () {
writer.end(() => {
writer = openTheStream(file, logSize, numBackups, options);
});
};
app.sighupHandler = function () {
debug('SIGHUP handler called.');
app.reopen();
};
app.shutdown = function (complete) {
sighupListeners.delete(app);
if (sighupListeners.size === 0 && mainSighupListenerStarted) {
process.removeListener('SIGHUP', mainSighupHandler);
mainSighupListenerStarted = false;
}
writer.end('', 'utf-8', complete);
};
// On SIGHUP, close and reopen all files. This allows this appender to work with
// logrotate. Note that if you are using logrotate, you should not set
// `logSize`.
sighupListeners.add(app);
if (!mainSighupListenerStarted) {
process.on('SIGHUP', mainSighupHandler);
mainSighupListenerStarted = true;
}
return app;
}
function configure(config, layouts) {
let layout = layouts.basicLayout;
if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
// security default (instead of relying on streamroller default)
config.mode = config.mode || 0o600;
return fileAppender(
config.filename,
layout,
config.maxLogSize,
config.backups,
config,
config.timezoneOffset
);
}
module.exports.configure = configure;

258
node_modules/log4js/lib/appenders/fileSync.js generated vendored Executable file
View File

@@ -0,0 +1,258 @@
const debug = require('debug')('log4js:fileSync');
const path = require('path');
const fs = require('fs');
const os = require('os');
const eol = os.EOL;
function touchFile(file, options) {
// attempt to create the directory
const mkdir = (dir) => {
try {
return fs.mkdirSync(dir, { recursive: true });
} catch (e) {
// backward-compatible fs.mkdirSync for nodejs pre-10.12.0 (without recursive option)
// recursive creation of parent first
if (e.code === 'ENOENT') {
mkdir(path.dirname(dir));
return mkdir(dir);
}
// throw error for all except EEXIST and EROFS (read-only filesystem)
if (e.code !== 'EEXIST' && e.code !== 'EROFS') {
throw e;
}
// EEXIST: throw if file and not directory
// EROFS : throw if directory not found
else {
try {
if (fs.statSync(dir).isDirectory()) {
return dir;
}
throw e;
} catch (err) {
throw e;
}
}
}
};
mkdir(path.dirname(file));
// try to throw EISDIR, EROFS, EACCES
fs.appendFileSync(file, '', { mode: options.mode, flag: options.flags });
}
class RollingFileSync {
constructor(filename, maxLogSize, backups, options) {
debug('In RollingFileStream');
if (maxLogSize < 0) {
throw new Error(`maxLogSize (${maxLogSize}) should be > 0`);
}
this.filename = filename;
this.size = maxLogSize;
this.backups = backups;
this.options = options;
this.currentSize = 0;
function currentFileSize(file) {
let fileSize = 0;
try {
fileSize = fs.statSync(file).size;
} catch (e) {
// file does not exist
touchFile(file, options);
}
return fileSize;
}
this.currentSize = currentFileSize(this.filename);
}
shouldRoll() {
debug(
'should roll with current size %d, and max size %d',
this.currentSize,
this.size
);
return this.currentSize >= this.size;
}
roll(filename) {
const that = this;
const nameMatcher = new RegExp(`^${path.basename(filename)}`);
function justTheseFiles(item) {
return nameMatcher.test(item);
}
function index(filename_) {
return (
parseInt(filename_.slice(`${path.basename(filename)}.`.length), 10) || 0
);
}
function byIndex(a, b) {
return index(a) - index(b);
}
function increaseFileIndex(fileToRename) {
const idx = index(fileToRename);
debug(`Index of ${fileToRename} is ${idx}`);
if (that.backups === 0) {
fs.truncateSync(filename, 0);
} else if (idx < that.backups) {
// on windows, you can get a EEXIST error if you rename a file to an existing file
// so, we'll try to delete the file we're renaming to first
try {
fs.unlinkSync(`${filename}.${idx + 1}`);
} catch (e) {
// ignore err: if we could not delete, it's most likely that it doesn't exist
}
debug(`Renaming ${fileToRename} -> ${filename}.${idx + 1}`);
fs.renameSync(
path.join(path.dirname(filename), fileToRename),
`${filename}.${idx + 1}`
);
}
}
function renameTheFiles() {
// roll the backups (rename file.n to file.n+1, where n <= numBackups)
debug('Renaming the old files');
const files = fs.readdirSync(path.dirname(filename));
files
.filter(justTheseFiles)
.sort(byIndex)
.reverse()
.forEach(increaseFileIndex);
}
debug('Rolling, rolling, rolling');
renameTheFiles();
}
// eslint-disable-next-line no-unused-vars
write(chunk, encoding) {
const that = this;
function writeTheChunk() {
debug('writing the chunk to the file');
that.currentSize += chunk.length;
fs.appendFileSync(that.filename, chunk);
}
debug('in write');
if (this.shouldRoll()) {
this.currentSize = 0;
this.roll(this.filename);
}
writeTheChunk();
}
}
/**
* File Appender writing the logs to a text file. Supports rolling of logs by size.
*
* @param file the file log messages will be written to
* @param layout a function that takes a logevent and returns a string
* (defaults to basicLayout).
* @param logSize - the maximum size (in bytes) for a log file,
* if not provided then logs won't be rotated.
* @param numBackups - the number of log files to keep after logSize
* has been reached (default 5)
* @param options - options to be passed to the underlying stream
* @param timezoneOffset - optional timezone offset in minutes (default system local)
*/
function fileAppender(
file,
layout,
logSize,
numBackups,
options,
timezoneOffset
) {
if (typeof file !== 'string' || file.length === 0) {
throw new Error(`Invalid filename: ${file}`);
} else if (file.endsWith(path.sep)) {
throw new Error(`Filename is a directory: ${file}`);
} else if (file.indexOf(`~${path.sep}`) === 0) {
// handle ~ expansion: https://github.com/nodejs/node/issues/684
// exclude ~ and ~filename as these can be valid files
file = file.replace('~', os.homedir());
}
file = path.normalize(file);
numBackups = !numBackups && numBackups !== 0 ? 5 : numBackups;
debug(
'Creating fileSync appender (',
file,
', ',
logSize,
', ',
numBackups,
', ',
options,
', ',
timezoneOffset,
')'
);
function openTheStream(filePath, fileSize, numFiles) {
let stream;
if (fileSize) {
stream = new RollingFileSync(filePath, fileSize, numFiles, options);
} else {
stream = ((f) => {
// touch the file to apply flags (like w to truncate the file)
touchFile(f, options);
return {
write(data) {
fs.appendFileSync(f, data);
},
};
})(filePath);
}
return stream;
}
const logFile = openTheStream(file, logSize, numBackups);
return (loggingEvent) => {
logFile.write(layout(loggingEvent, timezoneOffset) + eol);
};
}
function configure(config, layouts) {
let layout = layouts.basicLayout;
if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
const options = {
flags: config.flags || 'a',
encoding: config.encoding || 'utf8',
mode: config.mode || 0o600,
};
return fileAppender(
config.filename,
layout,
config.maxLogSize,
config.backups,
options,
config.timezoneOffset
);
}
module.exports.configure = configure;

0
node_modules/log4js/lib/appenders/ignoreBrowser.js generated vendored Normal file
View File

182
node_modules/log4js/lib/appenders/index.js generated vendored Normal file
View File

@@ -0,0 +1,182 @@
const path = require('path');
const debug = require('debug')('log4js:appenders');
const configuration = require('../configuration');
const clustering = require('../clustering');
const levels = require('../levels');
const layouts = require('../layouts');
const adapters = require('./adapters');
// 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('logLevelFilter', require('./logLevelFilter'));
coreAppenders.set('categoryFilter', require('./categoryFilter'));
coreAppenders.set('noLogFilter', require('./noLogFilter'));
coreAppenders.set('file', require('./file'));
coreAppenders.set('dateFile', require('./dateFile'));
coreAppenders.set('fileSync', require('./fileSync'));
coreAppenders.set('tcp', require('./tcp'));
const appenders = new Map();
const tryLoading = (modulePath, config) => {
let resolvedPath;
try {
const modulePathCJS = `${modulePath}.cjs`;
resolvedPath = require.resolve(modulePathCJS);
debug('Loading module from ', modulePathCJS);
} catch (e) {
resolvedPath = modulePath;
debug('Loading module from ', modulePath);
}
try {
// eslint-disable-next-line global-require, import/no-dynamic-require
return require(resolvedPath);
} catch (e) {
// if the module was found, and we still got an error, then raise it
configuration.throwExceptionIf(
config,
e.code !== 'MODULE_NOT_FOUND',
`appender "${modulePath}" could not be loaded (error was: ${e})`
);
return undefined;
}
};
const loadAppenderModule = (type, config) =>
coreAppenders.get(type) ||
tryLoading(`./${type}`, config) ||
tryLoading(type, config) ||
(require.main &&
require.main.filename &&
tryLoading(path.join(path.dirname(require.main.filename), type), config)) ||
tryLoading(path.join(process.cwd(), type), config);
const appendersLoading = new Set();
const getAppender = (name, config) => {
if (appenders.has(name)) return appenders.get(name);
if (!config.appenders[name]) return false;
if (appendersLoading.has(name))
throw new Error(`Dependency loop detected for appender ${name}.`);
appendersLoading.add(name);
debug(`Creating appender ${name}`);
// eslint-disable-next-line no-use-before-define
const appender = createAppender(name, config);
appendersLoading.delete(name);
appenders.set(name, appender);
return appender;
};
const createAppender = (name, config) => {
const appenderConfig = config.appenders[name];
const appenderModule = appenderConfig.type.configure
? appenderConfig.type
: loadAppenderModule(appenderConfig.type, config);
configuration.throwExceptionIf(
config,
configuration.not(appenderModule),
`appender "${name}" is not valid (type "${appenderConfig.type}" could not be found)`
);
if (appenderModule.appender) {
process.emitWarning(
`Appender ${appenderConfig.type} exports an appender function.`,
'DeprecationWarning',
'log4js-node-DEP0001'
);
debug(
'[log4js-node-DEP0001]',
`DEPRECATION: Appender ${appenderConfig.type} exports an appender function.`
);
}
if (appenderModule.shutdown) {
process.emitWarning(
`Appender ${appenderConfig.type} exports a shutdown function.`,
'DeprecationWarning',
'log4js-node-DEP0002'
);
debug(
'[log4js-node-DEP0002]',
`DEPRECATION: Appender ${appenderConfig.type} exports a shutdown function.`
);
}
debug(`${name}: clustering.isMaster ? ${clustering.isMaster()}`);
debug(
// eslint-disable-next-line global-require
`${name}: appenderModule is ${require('util').inspect(appenderModule)}`
);
return clustering.onlyOnMaster(
() => {
debug(
`calling appenderModule.configure for ${name} / ${appenderConfig.type}`
);
return appenderModule.configure(
adapters.modifyConfig(appenderConfig),
layouts,
(appender) => getAppender(appender, config),
levels
);
},
/* istanbul ignore next: fn never gets called by non-master yet needed to pass config validation */ () => {}
);
};
const setup = (config) => {
appenders.clear();
appendersLoading.clear();
if (!config) {
return;
}
const usedAppenders = [];
Object.values(config.categories).forEach((category) => {
usedAppenders.push(...category.appenders);
});
Object.keys(config.appenders).forEach((name) => {
// dodgy hard-coding of special case for tcp-server and multiprocess which may not have
// any categories associated with it, but needs to be started up anyway
if (
usedAppenders.includes(name) ||
config.appenders[name].type === 'tcp-server' ||
config.appenders[name].type === 'multiprocess'
) {
getAppender(name, config);
}
});
};
const init = () => {
setup();
};
init();
configuration.addListener((config) => {
configuration.throwExceptionIf(
config,
configuration.not(configuration.anObject(config.appenders)),
'must have a property "appenders" of type object.'
);
const appenderNames = Object.keys(config.appenders);
configuration.throwExceptionIf(
config,
configuration.not(appenderNames.length),
'must define at least one appender.'
);
appenderNames.forEach((name) => {
configuration.throwExceptionIf(
config,
configuration.not(config.appenders[name].type),
`appender "${name}" is not valid (must be an object with property "type")`
);
});
});
configuration.addListener(setup);
module.exports = appenders;
module.exports.init = init;

20
node_modules/log4js/lib/appenders/logLevelFilter.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
function logLevelFilter(minLevelString, maxLevelString, appender, levels) {
const minLevel = levels.getLevel(minLevelString);
const maxLevel = levels.getLevel(maxLevelString, levels.FATAL);
return (logEvent) => {
const eventLevel = logEvent.level;
if (
minLevel.isLessThanOrEqualTo(eventLevel) &&
maxLevel.isGreaterThanOrEqualTo(eventLevel)
) {
appender(logEvent);
}
};
}
function configure(config, layouts, findAppender, levels) {
const appender = findAppender(config.appender);
return logLevelFilter(config.level, config.maxLevel, appender, levels);
}
module.exports.configure = configure;

91
node_modules/log4js/lib/appenders/multiFile.js generated vendored Normal file
View File

@@ -0,0 +1,91 @@
const debug = require('debug')('log4js:multiFile');
const path = require('path');
const fileAppender = require('./file');
const findFileKey = (property, event) =>
event[property] || event.context[property];
module.exports.configure = (config, layouts) => {
debug('Creating a multi-file appender');
const files = new Map();
const timers = new Map();
function checkForTimeout(fileKey) {
const timer = timers.get(fileKey);
const app = files.get(fileKey);
/* istanbul ignore else: failsafe */
if (timer && app) {
if (Date.now() - timer.lastUsed > timer.timeout) {
debug('%s not used for > %d ms => close', fileKey, timer.timeout);
clearInterval(timer.interval);
timers.delete(fileKey);
files.delete(fileKey);
app.shutdown((err) => {
if (err) {
debug('ignore error on file shutdown: %s', err.message);
}
});
}
} else {
// will never get here as files and timers are coupled to be added and deleted at same place
debug('timer or app does not exist');
}
}
const appender = (logEvent) => {
const fileKey = findFileKey(config.property, logEvent);
debug('fileKey for property ', config.property, ' is ', fileKey);
if (fileKey) {
let file = files.get(fileKey);
debug('existing file appender is ', file);
if (!file) {
debug('creating new file appender');
config.filename = path.join(config.base, fileKey + config.extension);
file = fileAppender.configure(config, layouts);
files.set(fileKey, file);
if (config.timeout) {
debug('creating new timer');
timers.set(fileKey, {
timeout: config.timeout,
lastUsed: Date.now(),
interval: setInterval(
checkForTimeout.bind(null, fileKey),
config.timeout
),
});
}
} else if (config.timeout) {
debug('%s extending activity', fileKey);
timers.get(fileKey).lastUsed = Date.now();
}
file(logEvent);
} else {
debug('No fileKey for logEvent, quietly ignoring this log event');
}
};
appender.shutdown = (cb) => {
let shutdownFunctions = files.size;
if (shutdownFunctions <= 0) {
cb();
}
let error;
timers.forEach((timer, fileKey) => {
debug('clearing timer for ', fileKey);
clearInterval(timer.interval);
});
files.forEach((app, fileKey) => {
debug('calling shutdown for ', fileKey);
app.shutdown((err) => {
error = error || err;
shutdownFunctions -= 1;
if (shutdownFunctions <= 0) {
cb(error);
}
});
});
};
return appender;
};

191
node_modules/log4js/lib/appenders/multiprocess.js generated vendored Normal file
View File

@@ -0,0 +1,191 @@
const debug = require('debug')('log4js:multiprocess');
const net = require('net');
const LoggingEvent = require('../LoggingEvent');
const END_MSG = '__LOG4JS__';
/**
* Creates a server, listening on config.loggerPort, config.loggerHost.
* Output goes to config.actualAppender (config.appender is used to
* set up that appender).
*/
function logServer(config, actualAppender, levels) {
/**
* Takes a utf-8 string, returns an object with
* the correct log properties.
*/
function deserializeLoggingEvent(clientSocket, msg) {
debug('(master) deserialising log event');
const loggingEvent = LoggingEvent.deserialise(msg);
loggingEvent.remoteAddress = clientSocket.remoteAddress;
loggingEvent.remotePort = clientSocket.remotePort;
return loggingEvent;
}
const server = net.createServer((clientSocket) => {
debug('(master) connection received');
clientSocket.setEncoding('utf8');
let logMessage = '';
function logTheMessage(msg) {
debug('(master) deserialising log event and sending to actual appender');
actualAppender(deserializeLoggingEvent(clientSocket, msg));
}
function chunkReceived(chunk) {
debug('(master) chunk of data received');
let event;
logMessage += chunk || '';
if (logMessage.indexOf(END_MSG) > -1) {
event = logMessage.slice(0, logMessage.indexOf(END_MSG));
logTheMessage(event);
logMessage = logMessage.slice(event.length + END_MSG.length) || '';
// check for more, maybe it was a big chunk
chunkReceived();
}
}
function handleError(error) {
const loggingEvent = {
startTime: new Date(),
categoryName: 'log4js',
level: levels.ERROR,
data: ['A worker log process hung up unexpectedly', error],
remoteAddress: clientSocket.remoteAddress,
remotePort: clientSocket.remotePort,
};
actualAppender(loggingEvent);
}
clientSocket.on('data', chunkReceived);
clientSocket.on('end', chunkReceived);
clientSocket.on('error', handleError);
});
server.listen(
config.loggerPort || 5000,
config.loggerHost || 'localhost',
(e) => {
debug('(master) master server listening, error was ', e);
// allow the process to exit, if this is the only socket active
server.unref();
}
);
function app(event) {
debug('(master) log event sent directly to actual appender (local event)');
return actualAppender(event);
}
app.shutdown = function (cb) {
debug('(master) master shutdown called, closing server');
server.close(cb);
};
return app;
}
function workerAppender(config) {
let canWrite = false;
const buffer = [];
let socket;
let shutdownAttempts = 3;
function write(loggingEvent) {
debug('(worker) Writing log event to socket');
socket.write(loggingEvent.serialise(), 'utf8');
socket.write(END_MSG, 'utf8');
}
function emptyBuffer() {
let evt;
debug('(worker) emptying worker buffer');
while ((evt = buffer.shift())) {
write(evt);
}
}
function createSocket() {
debug(
`(worker) worker appender creating socket to ${
config.loggerHost || 'localhost'
}:${config.loggerPort || 5000}`
);
socket = net.createConnection(
config.loggerPort || 5000,
config.loggerHost || 'localhost'
);
socket.on('connect', () => {
debug('(worker) worker socket connected');
emptyBuffer();
canWrite = true;
});
socket.on('timeout', socket.end.bind(socket));
socket.on('error', (e) => {
debug('connection error', e);
canWrite = false;
emptyBuffer();
});
socket.on('close', createSocket);
}
createSocket();
function log(loggingEvent) {
if (canWrite) {
write(loggingEvent);
} else {
debug(
'(worker) worker buffering log event because it cannot write at the moment'
);
buffer.push(loggingEvent);
}
}
log.shutdown = function (cb) {
debug('(worker) worker shutdown called');
if (buffer.length && shutdownAttempts) {
debug('(worker) worker buffer has items, waiting 100ms to empty');
shutdownAttempts -= 1;
setTimeout(() => {
log.shutdown(cb);
}, 100);
} else {
socket.removeAllListeners('close');
socket.end(cb);
}
};
return log;
}
function createAppender(config, appender, levels) {
if (config.mode === 'master') {
debug('Creating master appender');
return logServer(config, appender, levels);
}
debug('Creating worker appender');
return workerAppender(config);
}
function configure(config, layouts, findAppender, levels) {
let appender;
debug(`configure with mode = ${config.mode}`);
if (config.mode === 'master') {
if (!config.appender) {
debug(`no appender found in config ${config}`);
throw new Error('multiprocess master must have an "appender" defined');
}
debug(`actual appender is ${config.appender}`);
appender = findAppender(config.appender);
if (!appender) {
debug(`actual appender "${config.appender}" not found`);
throw new Error(
`multiprocess master appender "${config.appender}" not defined`
);
}
}
return createAppender(config, appender, levels);
}
module.exports.configure = configure;

43
node_modules/log4js/lib/appenders/noLogFilter.js generated vendored Normal file
View File

@@ -0,0 +1,43 @@
const debug = require('debug')('log4js:noLogFilter');
/**
* The function removes empty or null regexp from the array
* @param {string[]} regexp
* @returns {string[]} a filtered string array with not empty or null regexp
*/
function removeNullOrEmptyRegexp(regexp) {
const filtered = regexp.filter((el) => el != null && el !== '');
return filtered;
}
/**
* Returns a function that will exclude the events in case they match
* with the regular expressions provided
* @param {(string|string[])} filters contains the regexp that will be used for the evaluation
* @param {*} appender
* @returns {function}
*/
function noLogFilter(filters, appender) {
return (logEvent) => {
debug(`Checking data: ${logEvent.data} against filters: ${filters}`);
if (typeof filters === 'string') {
filters = [filters];
}
filters = removeNullOrEmptyRegexp(filters);
const regex = new RegExp(filters.join('|'), 'i');
if (
filters.length === 0 ||
logEvent.data.findIndex((value) => regex.test(value)) < 0
) {
debug('Not excluded, sending to appender');
appender(logEvent);
}
};
}
function configure(config, layouts, findAppender) {
const appender = findAppender(config.appender);
return noLogFilter(config.exclude, appender);
}
module.exports.configure = configure;

29
node_modules/log4js/lib/appenders/recording.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
const debug = require('debug')('log4js:recording');
const recordedEvents = [];
function configure() {
return function (logEvent) {
debug(
`received logEvent, number of events now ${recordedEvents.length + 1}`
);
debug('log event was ', logEvent);
recordedEvents.push(logEvent);
};
}
function replay() {
return recordedEvents.slice();
}
function reset() {
recordedEvents.length = 0;
}
module.exports = {
configure,
replay,
playback: replay,
reset,
erase: reset,
};

15
node_modules/log4js/lib/appenders/stderr.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
function stderrAppender(layout, timezoneOffset) {
return (loggingEvent) => {
process.stderr.write(`${layout(loggingEvent, timezoneOffset)}\n`);
};
}
function configure(config, layouts) {
let layout = layouts.colouredLayout;
if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
return stderrAppender(layout, config.timezoneOffset);
}
module.exports.configure = configure;

15
node_modules/log4js/lib/appenders/stdout.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
function stdoutAppender(layout, timezoneOffset) {
return (loggingEvent) => {
process.stdout.write(`${layout(loggingEvent, timezoneOffset)}\n`);
};
}
function configure(config, layouts) {
let layout = layouts.colouredLayout;
if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
return stdoutAppender(layout, config.timezoneOffset);
}
exports.configure = configure;

49
node_modules/log4js/lib/appenders/tcp-server.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
const debug = require('debug')('log4js:tcp-server');
const net = require('net');
const clustering = require('../clustering');
const LoggingEvent = require('../LoggingEvent');
const DELIMITER = '__LOG4JS__';
exports.configure = (config) => {
debug('configure called with ', config);
const server = net.createServer((socket) => {
let dataSoFar = '';
const send = (data) => {
if (data) {
dataSoFar += data;
if (dataSoFar.indexOf(DELIMITER)) {
const events = dataSoFar.split(DELIMITER);
if (!dataSoFar.endsWith(DELIMITER)) {
dataSoFar = events.pop();
} else {
dataSoFar = '';
}
events
.filter((e) => e.length)
.forEach((e) => {
clustering.send(LoggingEvent.deserialise(e));
});
} else {
dataSoFar = '';
}
}
};
socket.setEncoding('utf8');
socket.on('data', send);
socket.on('end', send);
});
server.listen(config.port || 5000, config.host || 'localhost', () => {
debug(`listening on ${config.host || 'localhost'}:${config.port || 5000}`);
server.unref();
});
return {
shutdown: (cb) => {
debug('shutdown called.');
server.close(cb);
},
};
};

92
node_modules/log4js/lib/appenders/tcp.js generated vendored Normal file
View File

@@ -0,0 +1,92 @@
const debug = require('debug')('log4js:tcp');
const net = require('net');
function appender(config, layout) {
let canWrite = false;
const buffer = [];
let socket;
let shutdownAttempts = 3;
let endMsg = '__LOG4JS__';
function write(loggingEvent) {
debug('Writing log event to socket');
canWrite = socket.write(`${layout(loggingEvent)}${endMsg}`, 'utf8');
}
function emptyBuffer() {
let evt;
debug('emptying buffer');
while ((evt = buffer.shift())) {
write(evt);
}
}
function createSocket() {
debug(
`appender creating socket to ${config.host || 'localhost'}:${
config.port || 5000
}`
);
endMsg = `${config.endMsg || '__LOG4JS__'}`;
socket = net.createConnection(
config.port || 5000,
config.host || 'localhost'
);
socket.on('connect', () => {
debug('socket connected');
emptyBuffer();
canWrite = true;
});
socket.on('drain', () => {
debug('drain event received, emptying buffer');
canWrite = true;
emptyBuffer();
});
socket.on('timeout', socket.end.bind(socket));
socket.on('error', (e) => {
debug('connection error', e);
canWrite = false;
emptyBuffer();
});
socket.on('close', createSocket);
}
createSocket();
function log(loggingEvent) {
if (canWrite) {
write(loggingEvent);
} else {
debug('buffering log event because it cannot write at the moment');
buffer.push(loggingEvent);
}
}
log.shutdown = function (cb) {
debug('shutdown called');
if (buffer.length && shutdownAttempts) {
debug('buffer has items, waiting 100ms to empty');
shutdownAttempts -= 1;
setTimeout(() => {
log.shutdown(cb);
}, 100);
} else {
socket.removeAllListeners('close');
socket.end(cb);
}
};
return log;
}
function configure(config, layouts) {
debug(`configure with config = ${config}`);
let layout = function (loggingEvent) {
return loggingEvent.serialise();
};
if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
return appender(config, layout);
}
module.exports.configure = configure;