Merge branch 'master' into downgrade-nyc

This commit is contained in:
Lam Wei Li 2022-07-26 17:13:02 +08:00 committed by GitHub
commit cbb12e450e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 91 additions and 69 deletions

View File

@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x, 18.x]
node-version: [8.x, 10.x, 12.x, 14.x, 16.x, 18.x]
os: [ubuntu-latest, windows-latest]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

View File

@ -1,3 +1,2 @@
**/.*
coverage
.github
.nyc_output

View File

@ -87,11 +87,11 @@
{% if site.google_analytics %}
<script>
(function (i, s, o, g, r, a, m) {
(function(i, s, o, g, r, a, m) {
i["GoogleAnalyticsObject"] = r;
(i[r] =
i[r] ||
function () {
function() {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date());

View File

@ -20,7 +20,7 @@ log4js.configure({
var logger = log4js.getLogger("cheese");
var app = express();
app.use(log4js.connectLogger(logger, { level: "info" }));
app.get("/", function (req, res) {
app.get("/", function(req, res) {
res.send("hello world");
});
app.listen(5000);

View File

@ -161,7 +161,7 @@ log4js.configure({
type: "pattern",
pattern: "%d %p %c %x{user} %m%n",
tokens: {
user: function (logEvent) {
user: function(logEvent) {
return AuthLibrary.currentUser();
},
},
@ -219,8 +219,8 @@ This example can also be found in examples/custom-layout.js.
```javascript
const log4js = require("log4js");
log4js.addLayout("json", function (config) {
return function (logEvent) {
log4js.addLayout("json", function(config) {
return function(logEvent) {
return JSON.stringify(logEvent) + config.separator;
};
});

View File

@ -3,7 +3,7 @@ const log4js = require('../lib/log4js');
log4js.addLayout(
'json',
(config) =>
function (logEvent) {
function(logEvent) {
return JSON.stringify(logEvent) + config.separator;
}
);

View File

@ -44,7 +44,7 @@ log4js.configure({
hipchat_room: process.env.HIPCHAT_ROOM || '< Room ID or Name >',
hipchat_from: 'Mr. Semantics',
hipchat_notify: false,
hipchat_response_callback: function (err, response, body) {
hipchat_response_callback: function(err, response, body) {
if (err || response.statusCode > 300) {
throw new Error('hipchat-notifier failed');
}

View File

@ -8,7 +8,7 @@ log4js.configure({
type: 'pattern',
pattern: '%[%r (%x{pid}) %p %c -%] %m%n',
tokens: {
pid: function () {
pid: function() {
return process.pid;
},
},

View File

@ -35,7 +35,7 @@ function appender(filename, pattern, layout, options, timezoneOffset) {
const writer = openTheStream(filename, pattern, options);
const app = function (logEvent) {
const app = function(logEvent) {
if (!writer.writable) {
return;
}
@ -44,7 +44,7 @@ function appender(filename, pattern, layout, options, timezoneOffset) {
}
};
app.shutdown = function (complete) {
app.shutdown = function(complete) {
writer.end('', 'utf-8', complete);
};

View File

@ -83,7 +83,7 @@ function fileAppender(
let writer = openTheStream(file, logSize, numBackups, options);
const app = function (loggingEvent) {
const app = function(loggingEvent) {
if (!writer.writable) {
return;
}
@ -100,18 +100,18 @@ function fileAppender(
}
};
app.reopen = function () {
app.reopen = function() {
writer.end(() => {
writer = openTheStream(file, logSize, numBackups, options);
});
};
app.sighupHandler = function () {
app.sighupHandler = function() {
debug('SIGHUP handler called.');
app.reopen();
};
app.shutdown = function (complete) {
app.shutdown = function(complete) {
sighupListeners.delete(app);
if (sighupListeners.size === 0 && mainSighupListenerStarted) {
process.removeListener('SIGHUP', mainSighupHandler);

View File

@ -78,7 +78,7 @@ function logServer(config, actualAppender, levels) {
return actualAppender(event);
}
app.shutdown = function (cb) {
app.shutdown = function(cb) {
debug('(master) master shutdown called, closing server');
server.close(cb);
};
@ -108,9 +108,8 @@ function workerAppender(config) {
function createSocket() {
debug(
`(worker) worker appender creating socket to ${
config.loggerHost || 'localhost'
}:${config.loggerPort || 5000}`
`(worker) worker appender creating socket to ${config.loggerHost ||
'localhost'}:${config.loggerPort || 5000}`
);
socket = net.createConnection(
config.loggerPort || 5000,
@ -142,7 +141,7 @@ function workerAppender(config) {
buffer.push(loggingEvent);
}
}
log.shutdown = function (cb) {
log.shutdown = function(cb) {
debug('(worker) worker shutdown called');
if (buffer.length && shutdownAttempts) {
debug('(worker) worker buffer has items, waiting 100ms to empty');

View File

@ -3,7 +3,7 @@ const debug = require('debug')('log4js:recording');
const recordedEvents = [];
function configure() {
return function (logEvent) {
return function(logEvent) {
debug(
`received logEvent, number of events now ${recordedEvents.length + 1}`
);

View File

@ -23,9 +23,8 @@ function appender(config, layout) {
function createSocket() {
debug(
`appender creating socket to ${config.host || 'localhost'}:${
config.port || 5000
}`
`appender creating socket to ${config.host ||
'localhost'}:${config.port || 5000}`
);
endMsg = `${config.endMsg || '__LOG4JS__'}`;
socket = net.createConnection(
@ -62,7 +61,7 @@ function appender(config, layout) {
}
}
log.shutdown = function (cb) {
log.shutdown = function(cb) {
debug('shutdown called');
if (buffer.length && shutdownAttempts) {
debug('buffer has items, waiting 100ms to empty');
@ -80,7 +79,7 @@ function appender(config, layout) {
function configure(config, layouts) {
debug(`configure with config = ${config}`);
let layout = function (loggingEvent) {
let layout = function(loggingEvent) {
return loggingEvent.serialise();
};
if (config.layout) {

View File

@ -130,8 +130,7 @@ function dummyLayout(loggingEvent) {
*/
function patternLayout(pattern, tokens) {
const TTCC_CONVERSION_PATTERN = '%r %p %c - %m%n';
const regex =
/%(-?[0-9]+)?(\.?-?[0-9]+)?([[\]cdhmnprzxXyflos%])(\{([^}]+)\})?|([^%]+)/;
const regex = /%(-?[0-9]+)?(\.?-?[0-9]+)?([[\]cdhmnprzxXyflos%])(\{([^}]+)\})?|([^%]+)/;
pattern = pattern || TTCC_CONVERSION_PATTERN;
@ -272,7 +271,7 @@ function patternLayout(pattern, tokens) {
// support for ESM as it uses url instead of path for file
/* istanbul ignore next: unsure how to simulate ESM for test coverage */
const convertFileURLToPath = function (filepath) {
const convertFileURLToPath = function(filepath) {
const urlPrefix = 'file://';
if (filepath.startsWith(urlPrefix)) {
// https://nodejs.org/api/url.html#urlfileurltopathurl
@ -386,7 +385,7 @@ function patternLayout(pattern, tokens) {
return replacement;
}
return function (loggingEvent) {
return function(loggingEvent) {
let formattedString = '';
let result;
let searchString = pattern;

View File

@ -141,11 +141,11 @@ function addLevelMethods(target) {
);
const isLevelMethod = levelMethod[0].toUpperCase() + levelMethod.slice(1);
Logger.prototype[`is${isLevelMethod}Enabled`] = function () {
Logger.prototype[`is${isLevelMethod}Enabled`] = function() {
return this.isLevelEnabled(level);
};
Logger.prototype[levelMethod] = function (...args) {
Logger.prototype[levelMethod] = function(...args) {
this.log(level, ...args);
};
}

View File

@ -34,9 +34,9 @@
},
"scripts": {
"prepare": "is-ci || husky install",
"pretest": "prettier --check . && eslint \"lib/**/*.js\" \"test/**/*.js\"",
"prettier:fix": "prettier --write .",
"test": "tap \"test/tap/**/*.js\" --cov --timeout=45",
"pretest": "prettier --check \"**/*.*\" && eslint \"lib/**/*.js\" \"test/**/*.js\"",
"prettier:fix": "prettier --write \"**/*.*\"",
"test": "tap \"test/tap/**/*.js\" --cov --reporter=classic --timeout=45",
"typings": "tsc -p types/tsconfig.json"
},
"directories": {
@ -66,7 +66,7 @@
"husky": "^8.0.1",
"is-ci": "^3.0.1",
"nyc": "^14.1.1",
"prettier": "^2.7.1",
"prettier": "^1.19.1",
"proxyquire": "^2.1.3",
"tap": "^14.11.0",
"typescript": "^4.7.4"
@ -74,6 +74,20 @@
"browser": {
"os": false
},
"prettier": {
"trailingComma": "es5",
"arrowParens": "always",
"overrides": [
{
"files": [
"*.cjs"
],
"options": {
"parser": "typescript"
}
}
]
},
"tap": {
"check-coverage": true
},

View File

@ -55,8 +55,9 @@ test('log4js category inherit all appenders from direct parent', (batch) => {
log4js.configure(config);
const child1CategoryName = 'catA.catB.cat1';
const child1Appenders =
categories.appendersForCategory(child1CategoryName);
const child1Appenders = categories.appendersForCategory(
child1CategoryName
);
const child1Level = categories.getLevelForCategory(child1CategoryName);
t.equal(child1Appenders.length, 1, 'inherited 1 appender');
@ -67,8 +68,9 @@ test('log4js category inherit all appenders from direct parent', (batch) => {
t.equal(child1Level.levelStr, 'DEBUG', 'child level overrides parent');
const child2CategoryName = 'catA.catB.cat2';
const child2Appenders =
categories.appendersForCategory(child2CategoryName);
const child2Appenders = categories.appendersForCategory(
child2CategoryName
);
const child2Level = categories.getLevelForCategory(child2CategoryName);
t.ok(child2Appenders);
@ -122,8 +124,9 @@ test('log4js category inherit all appenders from direct parent', (batch) => {
);
const firstParentName = 'catA.catB';
const firstParentAppenders =
categories.appendersForCategory(firstParentName);
const firstParentAppenders = categories.appendersForCategory(
firstParentName
);
t.ok(firstParentAppenders);
t.equal(firstParentAppenders.length, 2, 'ended up with 2 appenders');

View File

@ -318,8 +318,9 @@ test('log4js configuration validation', (batch) => {
`${path.join(mainPath, '../../node_modules/nyc/bin/cheese')}`
] = testAppender('correct', result);
// in tap v15, the main path is at root of log4js (run `DEBUG=log4js:appenders npm test > /dev/null` to check)
sandboxConfig.requires[`${path.join(mainPath, '../../cheese')}`] =
testAppender('correct', result);
sandboxConfig.requires[
`${path.join(mainPath, '../../cheese')}`
] = testAppender('correct', result);
// in node v6, there's an extra layer of node modules for some reason, so add this one to work around it
sandboxConfig.requires[
`${path.join(

View File

@ -8,10 +8,10 @@ class MockLogger {
constructor() {
this.level = levels.TRACE;
this.messages = [];
this.log = function (level, message) {
this.log = function(level, message) {
this.messages.push({ level, message });
};
this.isLevelEnabled = function (level) {
this.isLevelEnabled = function(level) {
return level.isGreaterThanOrEqualTo(this.level);
};
}

View File

@ -9,11 +9,11 @@ class MockLogger {
this.messages = [];
this.level = levels.TRACE;
this.log = function (level, message) {
this.log = function(level, message) {
this.messages.push({ level, message });
};
this.isLevelEnabled = function (level) {
this.isLevelEnabled = function(level) {
return level.isGreaterThanOrEqualTo(this.level);
};
}

View File

@ -3,8 +3,9 @@ const debug = require('debug');
const sandbox = require('@log4js-node/sandboxed-module');
test('default settings', (batch) => {
const originalListener =
process.listeners('warning')[process.listeners('warning').length - 1];
const originalListener = process.listeners('warning')[
process.listeners('warning').length - 1
];
const warningListener = (error) => {
if (error.name === 'DeprecationWarning') {
if (
@ -48,7 +49,7 @@ test('default settings', (batch) => {
name: 'stdout',
appender() {
// deprecated
return function (evt) {
return function(evt) {
output.push(evt);
};
},

View File

@ -13,8 +13,9 @@ test('file appender single SIGHUP handler', (t) => {
const initialListeners = process.listenerCount('SIGHUP');
let warning;
const originalListener =
process.listeners('warning')[process.listeners('warning').length - 1];
const originalListener = process.listeners('warning')[
process.listeners('warning').length - 1
];
const warningListener = (error) => {
if (
error.type === 'SIGHUP' &&

View File

@ -249,8 +249,9 @@ test('log4js layouts', (batch) => {
});
batch.test('patternLayout', (t) => {
const originalListener =
process.listeners('warning')[process.listeners('warning').length - 1];
const originalListener = process.listeners('warning')[
process.listeners('warning').length - 1
];
const warningListener = (error) => {
if (error.name === 'DeprecationWarning') {
if (
@ -923,7 +924,7 @@ test('log4js layouts', (batch) => {
t.test('should be able to add a layout', (assert) => {
layouts.addLayout('test_layout', (config) => {
assert.equal(config, 'test_config');
return function (logEvent) {
return function(logEvent) {
return `TEST LAYOUT >${logEvent.data}`;
};
});

View File

@ -255,7 +255,7 @@ test('../../lib/logger', (batch) => {
batch.test('should correctly change the parseCallStack function', (t) => {
const logger = new Logger('stack');
const parseFunction = function () {
const parseFunction = function() {
return {
functionName: 'test function name',
fileName: 'test file name',

View File

@ -121,7 +121,7 @@ test('log4js', (batch) => {
return null;
}
thing.shutdown = function (cb) {
thing.shutdown = function(cb) {
events.shutdownCalled.push(true);
cb();
};
@ -196,7 +196,7 @@ test('log4js', (batch) => {
'./file': {
configure(configuration) {
appenderConfig = configuration;
return function () {};
return function() {};
},
},
},
@ -220,7 +220,7 @@ test('log4js', (batch) => {
const fakeStdoutAppender = {
configure() {
this.required = true;
return function (evt) {
return function(evt) {
fakeStdoutAppender.evt = evt;
};
},

View File

@ -134,8 +134,8 @@ test('multiFile appender', (batch) => {
layouts
);
const originalShutdown = fileAppender.shutdown;
fileAppender.shutdown = function (complete) {
const onCallback = function () {
fileAppender.shutdown = function(complete) {
const onCallback = function() {
complete(error);
};
originalShutdown(onCallback);

View File

@ -181,7 +181,7 @@ test('TCP Appender', (batch) => {
log4js.addLayout(
'json',
() =>
function (logEvent) {
function(logEvent) {
return JSON.stringify({
time: logEvent.startTime,
message: logEvent.data[0],

9
types/log4js.d.ts vendored
View File

@ -335,7 +335,12 @@ export interface Appenders {
}
export interface AppenderModule {
configure: (config: Config, layouts: LayoutsParam) => AppenderFunction;
configure: (
config?: Config,
layouts?: LayoutsParam,
findAppender?: () => AppenderFunction,
levels?: Levels
) => AppenderFunction;
}
export type AppenderFunction = (loggingEvent: LoggingEvent) => void;
@ -395,7 +400,7 @@ export interface Configuration {
}
export interface Recording {
configure(loggingEvent: LoggingEvent): void;
configure(): AppenderFunction;
replay(): LoggingEvent[];
playback(): LoggingEvent[];
reset(): void;

View File

@ -35,7 +35,7 @@ log4js.configure({
log4js.addLayout(
'json',
(config) =>
function (logEvent) {
function(logEvent) {
return JSON.stringify(logEvent) + config.separator;
}
);