mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 22:23:33 +01:00
pad_utils: Custom logger interface for warnDeprecated
This commit is contained in:
parent
248c114547
commit
908175d1ca
2 changed files with 29 additions and 2 deletions
|
@ -98,7 +98,8 @@ const padutils = {
|
||||||
* - This makes it possible to see the stack if the code runs in Node.js.
|
* - This makes it possible to see the stack if the code runs in Node.js.
|
||||||
* - Users are more likely to paste the stack in bug reports they might file.
|
* - Users are more likely to paste the stack in bug reports they might file.
|
||||||
*
|
*
|
||||||
* @param {...*} args - Passed to `console.warn`, with a stack trace appended.
|
* @param {...*} args - Passed to `padutils.warnDeprecated.logger.warn` (or `console.warn` if no
|
||||||
|
* logger is set), with a stack trace appended if available.
|
||||||
*/
|
*/
|
||||||
warnDeprecated: (...args) => {
|
warnDeprecated: (...args) => {
|
||||||
if (padutils.warnDeprecated.disabledForTestingOnly) return;
|
if (padutils.warnDeprecated.disabledForTestingOnly) return;
|
||||||
|
@ -106,7 +107,7 @@ const padutils = {
|
||||||
if (Error.captureStackTrace) Error.captureStackTrace(err, padutils.warnDeprecated);
|
if (Error.captureStackTrace) Error.captureStackTrace(err, padutils.warnDeprecated);
|
||||||
err.name = '';
|
err.name = '';
|
||||||
if (err.stack) args.push(err.stack);
|
if (err.stack) args.push(err.stack);
|
||||||
console.warn(...args);
|
(padutils.warnDeprecated.logger || console).warn(...args);
|
||||||
},
|
},
|
||||||
|
|
||||||
escapeHtml: (x) => Security.escapeHTML(String(x)),
|
escapeHtml: (x) => Security.escapeHTML(String(x)),
|
||||||
|
|
26
src/tests/backend/specs/pad_utils.js
Normal file
26
src/tests/backend/specs/pad_utils.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert').strict;
|
||||||
|
const {padutils} = require('../../../static/js/pad_utils');
|
||||||
|
|
||||||
|
describe(__filename, function () {
|
||||||
|
describe('warnDeprecated', function () {
|
||||||
|
const {warnDeprecated} = padutils;
|
||||||
|
const backups = {};
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
backups.logger = warnDeprecated.logger;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async function () {
|
||||||
|
warnDeprecated.logger = backups.logger;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('includes the stack', async function () {
|
||||||
|
let got;
|
||||||
|
warnDeprecated.logger = {warn: (stack) => got = stack};
|
||||||
|
warnDeprecated();
|
||||||
|
assert(got.includes(__filename));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue