Comparing version 6.4.2 to 6.4.3
# log4js-node changelog | ||
## 6.4.3 | ||
- chore(test): 100% test coverage - thanks [@peteriman](https://github.com/peteriman) | ||
- Part 1 of 3: https://github.com/log4js-node/log4js-node/pull/1200 | ||
- Part 2 of 3: https://github.com/log4js-node/log4js-node/pull/1204 | ||
- Part 3 of 3: https://github.com/log4js-node/log4js-node/pull/1205 | ||
- [chore(test): improved test cases](https://github.com/log4js-node/log4js-node/pull/1211) | ||
- [chore(validation): added filename validation](https://github.com/log4js-node/log4js-node/pull/1201) - thanks [@peteriman](https://github.com/peteriman) | ||
- [chore(improvement): do not initialise default appenders as it will be done again by configure()](https://github.com/log4js-node/log4js-node/pull/1210) - thanks [@peteriman](https://github.com/peteriman) | ||
- [chore(improvement): defensive coding for cluster=null if require('cluster') fails in try-catch ](https://github.com/log4js-node/log4js-node/pull/1199) - thanks [@peteriman](https://github.com/peteriman) | ||
- [chore(improvement): removed redundant logic in tcp-serverAppender](https://github.com/log4js-node/log4js-node/pull/1198) - thanks [@peteriman](https://github.com/peteriman) | ||
- [chore(improvement): removed redundant logic in multiprocessAppender](https://github.com/log4js-node/log4js-node/pull/1197) - thanks [@peteriman](https://github.com/peteriman) | ||
- [chore(docs): updated README.md with badges](https://github.com/log4js-node/log4js-node/pull/1209) - thanks [@peteriman](https://github.com/peteriman) | ||
- [chore(docs): added docs for istanbul ignore](https://github.com/log4js-node/log4js-node/pull/1208) - thanks [@peteriman](https://github.com/peteriman) | ||
- [chore(docs): updated logger api docs](https://github.com/log4js-node/log4js-node/pull/1203) - thanks [@peteriman](https://github.com/peteriman) | ||
- [chore(docs): updated file and fileSync appender docs](https://github.com/log4js-node/log4js-node/pull/1202) - thanks [@peteriman](https://github.com/peteriman) | ||
- [chore(lint): improve eslint rules](https://github.com/log4js-node/log4js-node/pull/1206) - thanks [@peteriman](https://github.com/peteriman) | ||
- [chore(dep): updated dependencies](https://github.com/log4js-node/log4js-node/pull/1207) - thanks [@peteriman](https://github.com/peteriman) | ||
- chore(dev): bump eslint from 8.10.0 to 8.11.0 | ||
- chore(dev): bump eslint-config-airbnb-base from 13.2.0 to 15.0.0 | ||
- chore(dev): bump eslint-config-prettier from 8.4.0 to 8.5.0 | ||
- chore(dev): bump tap from 15.1.6 to 16.0.0 | ||
- chore(dep): bump date-format from 4.0.4 to 4.0.5 | ||
- chore(dep): bump streamroller from 3.0.4 to 3.0.5 | ||
- chore(dep): updated package-lock.json | ||
## 6.4.2 | ||
@@ -4,0 +30,0 @@ |
@@ -23,3 +23,3 @@ function maxFileSizeUnitTransform(maxLogSize) { | ||
function adapter(configAdapter, config) { | ||
const newConfig = Object.assign({}, config); | ||
const newConfig = Object.assign({}, config); // eslint-disable-line prefer-object-spread | ||
Object.keys(configAdapter).forEach((key) => { | ||
@@ -26,0 +26,0 @@ if (newConfig[key]) { |
@@ -13,3 +13,4 @@ const streams = require('streamroller'); | ||
stream.on('error', (err) => { | ||
console.error('log4js.dateFileAppender - Writing to file %s, error happened ', filename, err); // eslint-disable-line | ||
// eslint-disable-next-line no-console | ||
console.error('log4js.dateFileAppender - Writing to file %s, error happened ', filename, err); | ||
}); | ||
@@ -16,0 +17,0 @@ stream.on("drain", () => { |
@@ -16,23 +16,6 @@ const debug = require('debug')('log4js:file'); | ||
function openTheStream(file, fileSize, numFiles, options) { | ||
const stream = new streams.RollingFileStream( | ||
file, | ||
fileSize, | ||
numFiles, | ||
options | ||
); | ||
stream.on('error', (err) => { | ||
console.error('log4js.fileAppender - Writing to file %s, error happened ', file, err); // eslint-disable-line | ||
}); | ||
stream.on('drain', () => { | ||
process.emit("log4js:pause", false); | ||
}); | ||
return stream; | ||
} | ||
/** | ||
* File Appender writing the logs to a text file. Supports rolling of logs by size. | ||
* | ||
* @param file file log messages will be written to | ||
* @param file the file log messages will be written to | ||
* @param layout a function that takes a logEvent and returns a string | ||
@@ -48,2 +31,5 @@ * (defaults to basicLayout). | ||
function fileAppender(file, layout, logSize, numBackups, options, timezoneOffset) { | ||
if (typeof file !== "string" || file.length === 0) { | ||
throw new Error(`Invalid filename: ${file}`); | ||
} | ||
file = path.normalize(file); | ||
@@ -61,2 +47,19 @@ numBackups = (!numBackups && numBackups !== 0) ? 5 : numBackups; | ||
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); | ||
@@ -63,0 +66,0 @@ |
@@ -6,3 +6,3 @@ const debug = require('debug')('log4js:fileSync'); | ||
const eol = os.EOL || '\n'; | ||
const eol = os.EOL; | ||
@@ -55,15 +55,11 @@ function touchFile(file, options) { | ||
class RollingFileSync { | ||
constructor(filename, size, backups, options) { | ||
constructor(filename, maxLogSize, backups, options) { | ||
debug('In RollingFileStream'); | ||
function throwErrorIfArgumentsAreNotValid() { | ||
if (!filename || !size || size <= 0) { | ||
throw new Error('You must specify a filename and file size'); | ||
} | ||
if (maxLogSize < 0) { | ||
throw new Error(`maxLogSize (${maxLogSize}) should be > 0`); | ||
} | ||
throwErrorIfArgumentsAreNotValid(); | ||
this.filename = filename; | ||
this.size = size; | ||
this.size = maxLogSize; | ||
this.backups = backups; | ||
@@ -106,10 +102,3 @@ this.options = options; | ||
function byIndex(a, b) { | ||
if (index(a) > index(b)) { | ||
return 1; | ||
} | ||
if (index(a) < index(b)) { | ||
return -1; | ||
} | ||
return 0; | ||
return index(a) - index(b); | ||
} | ||
@@ -148,3 +137,3 @@ | ||
/* eslint no-unused-vars:0 */ | ||
// eslint-disable-next-line no-unused-vars | ||
write(chunk, encoding) { | ||
@@ -175,3 +164,3 @@ const that = this; | ||
* | ||
* @param file file log messages will be written to | ||
* @param file the file log messages will be written to | ||
* @param layout a function that takes a logevent and returns a string | ||
@@ -183,11 +172,21 @@ * (defaults to basicLayout). | ||
* has been reached (default 5) | ||
* @param timezoneOffset - optional timezone offset in minutes | ||
* (default system local) | ||
* @param options - passed as is to fs options | ||
* @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, timezoneOffset, options) { | ||
debug('fileSync appender created'); | ||
function fileAppender(file, layout, logSize, numBackups, options, timezoneOffset) { | ||
if (typeof file !== "string" || file.length === 0) { | ||
throw new Error(`Invalid filename: ${file}`); | ||
} | ||
file = path.normalize(file); | ||
numBackups = (!numBackups && numBackups !== 0) ? 5 : numBackups; | ||
debug( | ||
'Creating fileSync appender (', | ||
file, ', ', | ||
logSize, ', ', | ||
numBackups, ', ', | ||
options, ', ', | ||
timezoneOffset, ')' | ||
); | ||
function openTheStream(filePath, fileSize, numFiles) { | ||
@@ -243,4 +242,4 @@ let stream; | ||
config.backups, | ||
config.timezoneOffset, | ||
options | ||
options, | ||
config.timezoneOffset | ||
); | ||
@@ -247,0 +246,0 @@ } |
@@ -27,3 +27,4 @@ const path = require('path'); | ||
try { | ||
return require(modulePath); // eslint-disable-line | ||
// eslint-disable-next-line global-require, import/no-dynamic-require | ||
return require(modulePath); | ||
} catch (e) { | ||
@@ -76,3 +77,4 @@ // if the module was found, and we still got an error, then raise it | ||
); | ||
debug(`DEPRECATION: Appender ${appenderConfig.type} exports an appender function.`); | ||
debug("[log4js-node-DEP0001]", | ||
`DEPRECATION: Appender ${appenderConfig.type} exports an appender function.`); | ||
} | ||
@@ -84,7 +86,8 @@ if (appenderModule.shutdown) { | ||
); | ||
debug(`DEPRECATION: Appender ${appenderConfig.type} exports a shutdown function.`); | ||
debug("[log4js-node-DEP0002]", | ||
`DEPRECATION: Appender ${appenderConfig.type} exports a shutdown function.`); | ||
} | ||
debug(`${name}: clustering.isMaster ? ${clustering.isMaster()}`); | ||
debug(`${name}: appenderModule is ${require('util').inspect(appenderModule)}`); // eslint-disable-line | ||
debug(`${name}: appenderModule is ${require('util').inspect(appenderModule)}`); // eslint-disable-line global-require | ||
return clustering.onlyOnMaster(() => { | ||
@@ -98,3 +101,3 @@ debug(`calling appenderModule.configure for ${name} / ${appenderConfig.type}`); | ||
); | ||
}, () => { }); | ||
}, /* istanbul ignore next: fn never gets called by non-master yet needed to pass config validation */ () => {}); | ||
}; | ||
@@ -105,2 +108,6 @@ | ||
appendersLoading.clear(); | ||
if (!config) { | ||
return; | ||
} | ||
const usedAppenders = []; | ||
@@ -121,3 +128,3 @@ Object.values(config.categories).forEach(category => { | ||
const init = () => { | ||
setup({ appenders: { out: { type: 'stdout' } }, categories: { default: { appenders: ['out'], level: 'trace' } } }); | ||
setup(); | ||
}; | ||
@@ -124,0 +131,0 @@ init(); |
@@ -17,2 +17,3 @@ | ||
const app = files.get(fileKey); | ||
/* istanbul ignore else: failsafe */ | ||
if (timer && app) { | ||
@@ -30,2 +31,5 @@ if (Date.now() - timer.lastUsed > timer.timeout) { | ||
} | ||
} 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'); | ||
} | ||
@@ -32,0 +36,0 @@ } |
@@ -28,4 +28,3 @@ | ||
/* eslint prefer-arrow-callback:0 */ | ||
const server = net.createServer(function connectionHandler(clientSocket) { | ||
const server = net.createServer((clientSocket) => { | ||
debug('(master) connection received'); | ||
@@ -36,6 +35,4 @@ clientSocket.setEncoding('utf8'); | ||
function logTheMessage(msg) { | ||
if (logMessage.length > 0) { | ||
debug('(master) deserialising log event and sending to actual appender'); | ||
actualAppender(deserializeLoggingEvent(clientSocket, msg)); | ||
} | ||
debug('(master) deserialising log event and sending to actual appender'); | ||
actualAppender(deserializeLoggingEvent(clientSocket, msg)); | ||
} | ||
@@ -73,3 +70,3 @@ | ||
server.listen(config.loggerPort || 5000, config.loggerHost || 'localhost', function (e) { | ||
server.listen(config.loggerPort || 5000, config.loggerHost || 'localhost', (e) => { | ||
debug('(master) master server listening, error was ', e); | ||
@@ -108,3 +105,2 @@ // allow the process to exit, if this is the only socket active | ||
debug('(worker) emptying worker buffer'); | ||
/* eslint no-cond-assign:0 */ | ||
while ((evt = buffer.shift())) { | ||
@@ -111,0 +107,0 @@ write(evt); |
@@ -10,44 +10,39 @@ const debug = require('debug')('log4js:tcp-server'); | ||
debug('configure called with ', config); | ||
// dummy shutdown if we're not master | ||
let shutdown = (cb) => { cb(); }; | ||
clustering.onlyOnMaster(() => { | ||
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)); | ||
}); | ||
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); | ||
}); | ||
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(); | ||
}); | ||
server.listen(config.port || 5000, config.host || 'localhost', () => { | ||
debug(`listening on ${config.host || 'localhost'}:${config.port || 5000}`); | ||
server.unref(); | ||
}); | ||
shutdown = (cb) => { | ||
return { | ||
shutdown: (cb) => { | ||
debug('shutdown called.'); | ||
server.close(cb); | ||
}; | ||
}); | ||
return { | ||
shutdown | ||
} | ||
}; | ||
}; |
@@ -21,3 +21,2 @@ | ||
debug('emptying buffer'); | ||
/* eslint no-cond-assign:0 */ | ||
while ((evt = buffer.shift())) { | ||
@@ -24,0 +23,0 @@ write(evt); |
@@ -8,3 +8,4 @@ const debug = require("debug")("log4js:clustering"); | ||
try { | ||
cluster = require("cluster"); //eslint-disable-line | ||
// eslint-disable-next-line global-require | ||
cluster = require("cluster"); | ||
} catch (e) { | ||
@@ -21,3 +22,3 @@ debug("cluster module not present"); | ||
const isPM2Master = () => pm2 && process.env[pm2InstanceVar] === "0"; | ||
const isMaster = () => disabled || cluster.isMaster || isPM2Master(); | ||
const isMaster = () => disabled || (cluster && cluster.isMaster) || isPM2Master(); | ||
@@ -77,3 +78,3 @@ const sendToListeners = logEvent => { | ||
process.on("message", receiver); | ||
} else if (cluster.isMaster) { | ||
} else if (cluster && cluster.isMaster) { | ||
debug("listening for cluster messages"); | ||
@@ -80,0 +81,0 @@ cluster.on("message", receiver); |
@@ -1,2 +0,2 @@ | ||
/* eslint-disable no-plusplus */ | ||
/* eslint no-underscore-dangle: ["error", { "allow": ["__statusCode", "_remoteAddress", "__headers", "_logging"] }] */ | ||
@@ -40,5 +40,5 @@ const levels = require("./levels"); | ||
// not === because token can be regexp object | ||
/* eslint eqeqeq:0 */ | ||
// eslint-disable-next-line eqeqeq | ||
if (a[i].token == a[j].token) { | ||
a.splice(j--, 1); | ||
a.splice(j--, 1); // eslint-disable-line no-plusplus | ||
} | ||
@@ -241,3 +241,2 @@ } | ||
module.exports = function getLogger(logger4js, options) { | ||
/* eslint no-underscore-dangle:0 */ | ||
if (typeof options === "string" || typeof options === "function") { | ||
@@ -244,0 +243,0 @@ options = { format: options }; |
@@ -163,3 +163,4 @@ const dateFormat = require('date-format'); | ||
); | ||
debug("DEPRECATION: Pattern %d{ABSOLUTE} is deprecated and replaced by %d{ABSOLUTETIME}."); | ||
debug("[log4js-node-DEP0003]", | ||
"DEPRECATION: Pattern %d{ABSOLUTE} is deprecated and replaced by %d{ABSOLUTETIME}."); | ||
// falls through | ||
@@ -176,3 +177,4 @@ case 'ABSOLUTETIME': | ||
); | ||
debug("DEPRECATION: Pattern %d{DATE} is deprecated and replaced by %d{DATETIME}."); | ||
debug("[log4js-node-DEP0004]", | ||
"DEPRECATION: Pattern %d{DATE} is deprecated and replaced by %d{DATETIME}."); | ||
// falls through | ||
@@ -276,3 +278,2 @@ case 'DATETIME': | ||
/* eslint quote-props:0 */ | ||
const replacers = { | ||
@@ -346,3 +347,2 @@ c: categoryName, | ||
/* eslint no-cond-assign:0 */ | ||
while ((result = regex.exec(searchString)) !== null) { | ||
@@ -349,0 +349,0 @@ // const matchedString = result[0]; |
@@ -1,2 +0,3 @@ | ||
/* eslint no-underscore-dangle:0 */ | ||
/* eslint no-underscore-dangle: ["error", { "allow": ["_log"] }] */ | ||
const debug = require("debug")("log4js:logger"); | ||
@@ -12,13 +13,23 @@ const LoggingEvent = require("./LoggingEvent"); | ||
function defaultParseCallStack(data, skipIdx = 4) { | ||
const stacklines = data.stack.split("\n").slice(skipIdx); | ||
const lineMatch = stackReg.exec(stacklines[0]); | ||
if (lineMatch && lineMatch.length === 6) { | ||
return { | ||
functionName: lineMatch[1], | ||
fileName: lineMatch[2], | ||
lineNumber: parseInt(lineMatch[3], 10), | ||
columnNumber: parseInt(lineMatch[4], 10), | ||
callStack: stacklines.join("\n") | ||
}; | ||
try { | ||
const stacklines = data.stack.split("\n").slice(skipIdx); | ||
const lineMatch = stackReg.exec(stacklines[0]); | ||
/* istanbul ignore else: failsafe */ | ||
if (lineMatch && lineMatch.length === 6) { | ||
return { | ||
functionName: lineMatch[1], | ||
fileName: lineMatch[2], | ||
lineNumber: parseInt(lineMatch[3], 10), | ||
columnNumber: parseInt(lineMatch[4], 10), | ||
callStack: stacklines.join("\n") | ||
}; | ||
} else { // eslint-disable-line no-else-return | ||
// will never get here unless nodejs has changes to Error | ||
console.error('log4js.logger - defaultParseCallStack error'); // eslint-disable-line no-console | ||
} | ||
} | ||
catch (err) { | ||
// will never get error unless nodejs has breaking changes to Error | ||
console.error('log4js.logger - defaultParseCallStack error', err); // eslint-disable-line no-console | ||
} | ||
return null; | ||
@@ -25,0 +36,0 @@ } |
@@ -22,3 +22,3 @@ const flatted = require('flatted'); | ||
this.level = level; | ||
this.context = Object.assign({}, context); | ||
this.context = Object.assign({}, context); // eslint-disable-line prefer-object-spread | ||
this.pid = process.pid; | ||
@@ -41,2 +41,3 @@ | ||
if (value && value.message && value.stack) { | ||
// eslint-disable-next-line prefer-object-spread | ||
value = Object.assign({message: value.message, stack: value.stack}, value); | ||
@@ -43,0 +44,0 @@ } |
{ | ||
"name": "log4js", | ||
"version": "6.4.2", | ||
"version": "6.4.3", | ||
"description": "Port of Log4js to work with node.", | ||
@@ -46,7 +46,7 @@ "homepage": "https://log4js-node.github.io/log4js-node/", | ||
"dependencies": { | ||
"date-format": "^4.0.4", | ||
"date-format": "^4.0.5", | ||
"debug": "^4.3.3", | ||
"flatted": "^3.2.5", | ||
"rfdc": "^1.3.0", | ||
"streamroller": "^3.0.4" | ||
"streamroller": "^3.0.5" | ||
}, | ||
@@ -58,5 +58,5 @@ "devDependencies": { | ||
"deep-freeze": "0.0.1", | ||
"eslint": "^8.10.0", | ||
"eslint-config-airbnb-base": "^13.2.0", | ||
"eslint-config-prettier": "^8.4.0", | ||
"eslint": "^8.11.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-import-resolver-node": "^0.3.6", | ||
@@ -70,3 +70,3 @@ "eslint-plugin-import": "^2.25.4", | ||
"proxyquire": "^2.1.3", | ||
"tap": "^15.1.6", | ||
"tap": "^16.0.0", | ||
"typescript": "^4.6.2", | ||
@@ -73,0 +73,0 @@ "validate-commit-msg": "^2.14.0" |
@@ -1,2 +0,3 @@ | ||
# log4js-node [![Build Status](https://secure.travis-ci.org/log4js-node/log4js-node.png?branch=master)](http://travis-ci.org/log4js-node/log4js-node) [![codecov](https://codecov.io/gh/log4js-node/log4js-node/branch/master/graph/badge.svg)](https://codecov.io/gh/log4js-node/log4js-node) | ||
log4js-node [![CodeQL](https://github.com/log4js-node/log4js-node/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/log4js-node/log4js-node/actions/workflows/codeql-analysis.yml) [![Node.js CI](https://github.com/log4js-node/log4js-node/actions/workflows/node.js.yml/badge.svg)](https://github.com/log4js-node/log4js-node/actions/workflows/node.js.yml) | ||
=========== | ||
@@ -3,0 +4,0 @@ [![NPM](https://nodei.co/npm/log4js.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/log4js/) |
@@ -142,3 +142,3 @@ import * as log4js from './log4js'; | ||
appenders: { rec: { type: 'recording' } }, | ||
categories: { default: { appenders: [ 'rec'], 'level': 'debug' } } | ||
categories: { default: { appenders: ['rec'], 'level': 'debug' } } | ||
}); | ||
@@ -154,2 +154,5 @@ const logger8 = log4js.getLogger(); | ||
} | ||
if (loggingEvents[0].data[0] !== 'This will go to the recording!') { | ||
throw new Error(`Expected message 'This will go to the recording!', got ${loggingEvents[0].data[0]}`) | ||
} | ||
if (loggingEvents[1].data[0] !== 'Another one') { | ||
@@ -156,0 +159,0 @@ throw new Error(`Expected message 'Another one', got ${loggingEvents[1].data[0]}`) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130763
2968
123
Updateddate-format@^4.0.5
Updatedstreamroller@^3.0.5