Skip to content

Commit

Permalink
Fix/log4js (#5766)
Browse files Browse the repository at this point in the history
* Updated log4js

* Updated log4js version.

* Removed requests and moved to axios.

* Fixed startup.

* Fixed windows dependency install.

* Fixed import export rate limiter.

* Fixed all log levels.
  • Loading branch information
SamTV12345 authored Oct 22, 2023
1 parent f64ddd9 commit f649b1e
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-package-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
src/bin/doc/package-lock.json
-
name: Install lockfile-lint
run: npm install --no-save lockfile-lint
run: npm install --no-save lockfile-lint --legacy-peer-deps
-
name: Run lockfile-lint on package-lock.json
run: >
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upgrade-from-latest-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
run: cd src && npm test
-
name: Install Cypress
run: cd src && npm install cypress
run: cd src && npm install cypress --legacy-peer-deps
-
name: Run Etherpad & Test Frontend
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
etherpad/src/bin/doc/package-lock.json
-
name: Install Cypress
run: cd etherpad && cd src && npm install cypress
run: cd etherpad && cd src && npm install cypress --legacy-peer-deps
-
name: Run Etherpad
run: |
Expand Down
2 changes: 1 addition & 1 deletion src/bin/installOnWindows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cd /D node_modules
mklink /D "ep_etherpad-lite" "..\src"

cd /D "ep_etherpad-lite"
cmd /C npm ci || exit /B 1
cmd /C npm ci --legacy-peer-deps || exit /B 1

cd /D "%~dp0\..\.."

Expand Down
17 changes: 10 additions & 7 deletions src/node/hooks/express/importexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ const securityManager = require('../../db/SecurityManager');
const webaccess = require('./webaccess');

exports.expressCreateServer = (hookName, args, cb) => {
settings.importExportRateLimiting.onLimitReached = (req, res, options) => {
// when the rate limiter triggers, write a warning in the logs
console.warn('Import/Export rate limiter triggered on ' +
`"${req.originalUrl}" for IP address ${req.ip}`);
};
// The rate limiter is created in this hook so that restarting the server resets the limiter.
const limiter = rateLimit(settings.importExportRateLimiting);
const limiter = rateLimit({
...settings.importExportRateLimiting,
handler: (request, response, next, options) => {
if (request.rateLimit.current === request.rateLimit.limit + 1) {
// when the rate limiter triggers, write a warning in the logs
console.warn('Import/Export rate limiter triggered on ' +
`"${request.originalUrl}" for IP address ${request.ip}`);
}
},
});

// handle export requests
args.app.use('/p/:pad/:rev?/export/:type', limiter);
Expand Down
1 change: 0 additions & 1 deletion src/node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/

const log4js = require('log4js');
log4js.replaceConsole();

const settings = require('./utils/Settings');

Expand Down
15 changes: 12 additions & 3 deletions src/node/utils/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,24 @@ const nonSettings = [

// This is a function to make it easy to create a new instance. It is important to not reuse a
// config object after passing it to log4js.configure() because that method mutates the object. :(
const defaultLogConfig = () => ({appenders: [{type: 'console'}]});
const defaultLogConfig = () => ({appenders: {console: {type: 'console'}},
categories: {
default: {appenders: ['console'], level: 'info'},
}});
const defaultLogLevel = 'INFO';

const initLogging = (logLevel, config) => {
// log4js.configure() modifies exports.logconfig so check for equality first.
const logConfigIsDefault = deepEqual(config, defaultLogConfig());
log4js.configure(config);
log4js.setGlobalLogLevel(logLevel);
log4js.replaceConsole();
log4js.getLogger('console');

// Overwrites for console output methods
console.debug = logger.debug.bind(logger);
console.log = logger.info.bind(logger);
console.warn = logger.warn.bind(logger);
console.error = logger.error.bind(logger);

// Log the warning after configuring log4js to increase the chances the user will see it.
if (!logConfigIsDefault) logger.warn('The logconfig setting is deprecated.');
};
Expand Down
117 changes: 86 additions & 31 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"jsonminify": "0.4.2",
"languages4translatewiki": "0.1.3",
"lodash.clonedeep": "4.5.0",
"log4js": "0.6.38",
"log4js": "^6.9.1",
"measured-core": "^2.0.0",
"mime-types": "^2.1.35",
"npm": "^6.14.18",
Expand Down Expand Up @@ -103,8 +103,7 @@
"scripts": {
"lint": "eslint .",
"test": "mocha --timeout 120000 --recursive tests/backend/specs ../node_modules/ep_*/static/tests/backend/specs",
"test-container": "mocha --timeout 5000 tests/container/specs/api",
"dev": "bash ./bin/run.sh"
"test-container": "mocha --timeout 5000 tests/container/specs/api"
},
"version": "1.9.3",
"license": "Apache-2.0"
Expand Down
3 changes: 0 additions & 3 deletions src/tests/backend/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ exports.init = async function () {
if (!logLevel.isLessThanOrEqualTo(log4js.levels.DEBUG)) {
logger.warn('Disabling non-test logging for the duration of the test. ' +
'To enable non-test logging, change the loglevel setting to DEBUG.');
log4js.setGlobalLogLevel(log4js.levels.OFF);
logger.setLevel(logLevel);
}

// Note: This is only a shallow backup.
Expand All @@ -66,7 +64,6 @@ exports.init = async function () {
webaccess.authnFailureDelayMs = backups.authnFailureDelayMs;
// Note: This does not unset settings that were added.
Object.assign(settings, backups.settings);
log4js.setGlobalLogLevel(logLevel);
await server.exit();
});

Expand Down

0 comments on commit f649b1e

Please sign in to comment.