settings: Use a log4js logger instead of console
This commit is contained in:
parent
653dbb3449
commit
7653dc650d
1 changed files with 38 additions and 37 deletions
|
@ -39,9 +39,11 @@ const suppressDisableMsg = ' -- To suppress these warning messages change ' +
|
||||||
'suppressErrorsInPadText to true in your settings.json\n';
|
'suppressErrorsInPadText to true in your settings.json\n';
|
||||||
const _ = require('underscore');
|
const _ = require('underscore');
|
||||||
|
|
||||||
|
const logger = log4js.getLogger('settings');
|
||||||
|
|
||||||
/* Root path of the installation */
|
/* Root path of the installation */
|
||||||
exports.root = absolutePaths.findEtherpadRoot();
|
exports.root = absolutePaths.findEtherpadRoot();
|
||||||
console.log('All relative paths will be interpreted relative to the identified ' +
|
logger.info('All relative paths will be interpreted relative to the identified ' +
|
||||||
`Etherpad base dir: ${exports.root}`);
|
`Etherpad base dir: ${exports.root}`);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -450,7 +452,7 @@ exports.getGitCommit = () => {
|
||||||
}
|
}
|
||||||
version = version.substring(0, 7);
|
version = version.substring(0, 7);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`Can't get git version for server header\n${e.message}`);
|
logger.warn(`Can't get git version for server header\n${e.message}`);
|
||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
};
|
};
|
||||||
|
@ -469,7 +471,7 @@ const storeSettings = (settingsObj) => {
|
||||||
for (const i of Object.keys(settingsObj || {})) {
|
for (const i of Object.keys(settingsObj || {})) {
|
||||||
// test if the setting starts with a lowercase character
|
// test if the setting starts with a lowercase character
|
||||||
if (i.charAt(0).search('[a-z]') !== 0) {
|
if (i.charAt(0).search('[a-z]') !== 0) {
|
||||||
console.warn(`Settings should start with a lowercase character: '${i}'`);
|
logger.warn(`Settings should start with a lowercase character: '${i}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we know this setting, so we overwrite it
|
// we know this setting, so we overwrite it
|
||||||
|
@ -482,7 +484,7 @@ const storeSettings = (settingsObj) => {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// this setting is unknown, output a warning and throw it away
|
// this setting is unknown, output a warning and throw it away
|
||||||
console.warn(`Unknown Setting: '${i}'. This setting doesn't exist or it was removed`);
|
logger.warn(`Unknown Setting: '${i}'. This setting doesn't exist or it was removed`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -598,7 +600,7 @@ const lookupEnvironmentVariables = (obj) => {
|
||||||
const defaultValue = match[3];
|
const defaultValue = match[3];
|
||||||
|
|
||||||
if ((envVarValue === undefined) && (defaultValue === undefined)) {
|
if ((envVarValue === undefined) && (defaultValue === undefined)) {
|
||||||
console.warn(`Environment variable "${envVarName}" does not contain any value for ` +
|
logger.warn(`Environment variable "${envVarName}" does not contain any value for ` +
|
||||||
`configuration key "${key}", and no default was given. Using null. ` +
|
`configuration key "${key}", and no default was given. Using null. ` +
|
||||||
'THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF ETHERPAD; you should ' +
|
'THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF ETHERPAD; you should ' +
|
||||||
'explicitly use "null" as the default if you want to continue to use null.');
|
'explicitly use "null" as the default if you want to continue to use null.');
|
||||||
|
@ -611,7 +613,7 @@ const lookupEnvironmentVariables = (obj) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((envVarValue === undefined) && (defaultValue !== undefined)) {
|
if ((envVarValue === undefined) && (defaultValue !== undefined)) {
|
||||||
console.debug(`Environment variable "${envVarName}" not found for ` +
|
logger.debug(`Environment variable "${envVarName}" not found for ` +
|
||||||
`configuration key "${key}". Falling back to default value.`);
|
`configuration key "${key}". Falling back to default value.`);
|
||||||
|
|
||||||
return coerceValue(defaultValue);
|
return coerceValue(defaultValue);
|
||||||
|
@ -623,7 +625,7 @@ const lookupEnvironmentVariables = (obj) => {
|
||||||
* For numeric and boolean strings let's convert it to proper types before
|
* For numeric and boolean strings let's convert it to proper types before
|
||||||
* returning it, in order to maintain backward compatibility.
|
* returning it, in order to maintain backward compatibility.
|
||||||
*/
|
*/
|
||||||
console.debug(
|
logger.debug(
|
||||||
`Configuration key "${key}" will be read from environment variable "${envVarName}"`);
|
`Configuration key "${key}" will be read from environment variable "${envVarName}"`);
|
||||||
|
|
||||||
return coerceValue(envVarValue);
|
return coerceValue(envVarValue);
|
||||||
|
@ -650,11 +652,11 @@ const parseSettings = (settingsFilename, isSettings) => {
|
||||||
if (isSettings) {
|
if (isSettings) {
|
||||||
settingsType = 'settings';
|
settingsType = 'settings';
|
||||||
notFoundMessage = 'Continuing using defaults!';
|
notFoundMessage = 'Continuing using defaults!';
|
||||||
notFoundFunction = console.warn;
|
notFoundFunction = logger.warn.bind(logger);
|
||||||
} else {
|
} else {
|
||||||
settingsType = 'credentials';
|
settingsType = 'credentials';
|
||||||
notFoundMessage = 'Ignoring.';
|
notFoundMessage = 'Ignoring.';
|
||||||
notFoundFunction = console.info;
|
notFoundFunction = logger.info.bind(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -672,13 +674,13 @@ const parseSettings = (settingsFilename, isSettings) => {
|
||||||
|
|
||||||
const settings = JSON.parse(settingsStr);
|
const settings = JSON.parse(settingsStr);
|
||||||
|
|
||||||
console.info(`${settingsType} loaded from: ${settingsFilename}`);
|
logger.info(`${settingsType} loaded from: ${settingsFilename}`);
|
||||||
|
|
||||||
const replacedSettings = lookupEnvironmentVariables(settings);
|
const replacedSettings = lookupEnvironmentVariables(settings);
|
||||||
|
|
||||||
return replacedSettings;
|
return replacedSettings;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`There was an error processing your ${settingsType} ` +
|
logger.error(`There was an error processing your ${settingsType} ` +
|
||||||
`file from ${settingsFilename}: ${e.message}`);
|
`file from ${settingsFilename}: ${e.message}`);
|
||||||
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -706,7 +708,7 @@ exports.reloadSettings = () => {
|
||||||
log4js.replaceConsole();
|
log4js.replaceConsole();
|
||||||
|
|
||||||
if (!exports.skinName) {
|
if (!exports.skinName) {
|
||||||
console.warn('No "skinName" parameter found. Please check out settings.json.template and ' +
|
logger.warn('No "skinName" parameter found. Please check out settings.json.template and ' +
|
||||||
'update your settings.json. Falling back to the default "colibris".');
|
'update your settings.json. Falling back to the default "colibris".');
|
||||||
exports.skinName = 'colibris';
|
exports.skinName = 'colibris';
|
||||||
}
|
}
|
||||||
|
@ -717,7 +719,7 @@ exports.reloadSettings = () => {
|
||||||
const countPieces = exports.skinName.split(path.sep).length;
|
const countPieces = exports.skinName.split(path.sep).length;
|
||||||
|
|
||||||
if (countPieces !== 1) {
|
if (countPieces !== 1) {
|
||||||
console.error(`skinName must be the name of a directory under "${skinBasePath}". This is ` +
|
logger.error(`skinName must be the name of a directory under "${skinBasePath}". This is ` +
|
||||||
`not valid: "${exports.skinName}". Falling back to the default "colibris".`);
|
`not valid: "${exports.skinName}". Falling back to the default "colibris".`);
|
||||||
|
|
||||||
exports.skinName = 'colibris';
|
exports.skinName = 'colibris';
|
||||||
|
@ -728,7 +730,7 @@ exports.reloadSettings = () => {
|
||||||
|
|
||||||
// what if someone sets skinName == ".." or "."? We catch him!
|
// what if someone sets skinName == ".." or "."? We catch him!
|
||||||
if (absolutePaths.isSubdir(skinBasePath, skinPath) === false) {
|
if (absolutePaths.isSubdir(skinBasePath, skinPath) === false) {
|
||||||
console.error(`Skin path ${skinPath} must be a subdirectory of ${skinBasePath}. ` +
|
logger.error(`Skin path ${skinPath} must be a subdirectory of ${skinBasePath}. ` +
|
||||||
'Falling back to the default "colibris".');
|
'Falling back to the default "colibris".');
|
||||||
|
|
||||||
exports.skinName = 'colibris';
|
exports.skinName = 'colibris';
|
||||||
|
@ -736,13 +738,12 @@ exports.reloadSettings = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs.existsSync(skinPath) === false) {
|
if (fs.existsSync(skinPath) === false) {
|
||||||
console.error(
|
logger.error(`Skin path ${skinPath} does not exist. Falling back to the default "colibris".`);
|
||||||
`Skin path ${skinPath} does not exist. Falling back to the default "colibris".`);
|
|
||||||
exports.skinName = 'colibris';
|
exports.skinName = 'colibris';
|
||||||
skinPath = path.join(skinBasePath, exports.skinName);
|
skinPath = path.join(skinBasePath, exports.skinName);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info(`Using skin "${exports.skinName}" in dir: ${skinPath}`);
|
logger.info(`Using skin "${exports.skinName}" in dir: ${skinPath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exports.abiword) {
|
if (exports.abiword) {
|
||||||
|
@ -754,7 +755,7 @@ exports.reloadSettings = () => {
|
||||||
if (!exports.suppressErrorsInPadText) {
|
if (!exports.suppressErrorsInPadText) {
|
||||||
exports.defaultPadText += `\nError: ${abiwordError}${suppressDisableMsg}`;
|
exports.defaultPadText += `\nError: ${abiwordError}${suppressDisableMsg}`;
|
||||||
}
|
}
|
||||||
console.error(`${abiwordError} File location: ${exports.abiword}`);
|
logger.error(`${abiwordError} File location: ${exports.abiword}`);
|
||||||
exports.abiword = null;
|
exports.abiword = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -770,7 +771,7 @@ exports.reloadSettings = () => {
|
||||||
if (!exports.suppressErrorsInPadText) {
|
if (!exports.suppressErrorsInPadText) {
|
||||||
exports.defaultPadText += `\nError: ${sofficeError}${suppressDisableMsg}`;
|
exports.defaultPadText += `\nError: ${sofficeError}${suppressDisableMsg}`;
|
||||||
}
|
}
|
||||||
console.error(`${sofficeError} File location: ${exports.soffice}`);
|
logger.error(`${sofficeError} File location: ${exports.soffice}`);
|
||||||
exports.soffice = null;
|
exports.soffice = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -780,15 +781,15 @@ exports.reloadSettings = () => {
|
||||||
const sessionkeyFilename = absolutePaths.makeAbsolute(argv.sessionkey || './SESSIONKEY.txt');
|
const sessionkeyFilename = absolutePaths.makeAbsolute(argv.sessionkey || './SESSIONKEY.txt');
|
||||||
try {
|
try {
|
||||||
exports.sessionKey = fs.readFileSync(sessionkeyFilename, 'utf8');
|
exports.sessionKey = fs.readFileSync(sessionkeyFilename, 'utf8');
|
||||||
console.info(`Session key loaded from: ${sessionkeyFilename}`);
|
logger.info(`Session key loaded from: ${sessionkeyFilename}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.info(
|
logger.info(
|
||||||
`Session key file "${sessionkeyFilename}" not found. Creating with random contents.`);
|
`Session key file "${sessionkeyFilename}" not found. Creating with random contents.`);
|
||||||
exports.sessionKey = randomString(32);
|
exports.sessionKey = randomString(32);
|
||||||
fs.writeFileSync(sessionkeyFilename, exports.sessionKey, 'utf8');
|
fs.writeFileSync(sessionkeyFilename, exports.sessionKey, 'utf8');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn('Declaring the sessionKey in the settings.json is deprecated. ' +
|
logger.warn('Declaring the sessionKey in the settings.json is deprecated. ' +
|
||||||
'This value is auto-generated now. Please remove the setting from the file. -- ' +
|
'This value is auto-generated now. Please remove the setting from the file. -- ' +
|
||||||
'If you are seeing this error after restarting using the Admin User ' +
|
'If you are seeing this error after restarting using the Admin User ' +
|
||||||
'Interface then you can ignore this message.');
|
'Interface then you can ignore this message.');
|
||||||
|
@ -801,12 +802,12 @@ exports.reloadSettings = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.dbSettings.filename = absolutePaths.makeAbsolute(exports.dbSettings.filename);
|
exports.dbSettings.filename = absolutePaths.makeAbsolute(exports.dbSettings.filename);
|
||||||
console.warn(`${dirtyWarning} File location: ${exports.dbSettings.filename}`);
|
logger.warn(`${dirtyWarning} File location: ${exports.dbSettings.filename}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exports.ip === '') {
|
if (exports.ip === '') {
|
||||||
// using Unix socket for connectivity
|
// using Unix socket for connectivity
|
||||||
console.warn('The settings file contains an empty string ("") for the "ip" parameter. The ' +
|
logger.warn('The settings file contains an empty string ("") for the "ip" parameter. The ' +
|
||||||
'"port" parameter will be interpreted as the path to a Unix socket to bind at.');
|
'"port" parameter will be interpreted as the path to a Unix socket to bind at.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -822,7 +823,7 @@ exports.reloadSettings = () => {
|
||||||
* TODO: remove the "?v=randomstring" parameter, and replace with hashed filenames instead
|
* TODO: remove the "?v=randomstring" parameter, and replace with hashed filenames instead
|
||||||
*/
|
*/
|
||||||
exports.randomVersionString = randomString(4);
|
exports.randomVersionString = randomString(4);
|
||||||
console.log(`Random string used for versioning assets: ${exports.randomVersionString}`);
|
logger.info(`Random string used for versioning assets: ${exports.randomVersionString}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.exportedForTestingOnly = {
|
exports.exportedForTestingOnly = {
|
||||||
|
|
Loading…
Reference in a new issue