feat: Add server command line option for logs filtering
MODIFY
docs/en/writing-running-appium/server-args.md
docs/en/writing-running-appium/server-args.md
@@ -95,3 +95,4 @@ All flags are optional, but some are required in conjunction with certain others
|`--relaxed-security`|false|Disable additional security checks, so it is possible to use some advanced features, provided by drivers supporting this option. Only enable it if all the clients are in the trusted network and it is not the case if a client could potentially break out of the session sandbox. Can override enabling of specific features with --deny-insecure. See also the [security doc](/docs/en/writing-running-appium/security.md)||
|`--allow-insecure`|[]|Allow a list of features which are considered insecure and must be turned on explicitly by system administrators. Feature names are documented by the relevant server/driver. Should be a comma-separated list, or a path to a filename containing one feature name per line. Features listed in --deny-insecure will override anything listed here. Does not make sense to use in conjunction with --relaxed-security. See also the [security doc](/docs/en/writing-running-appium/security.md)|`--allow-insecure=foo,bar`|
|`--deny-insecure`|[]|Specify a list of features which will never be allowed to run, even if --relaxed-security is turned on, and even if feature names are listed with --allow-insecure. Should be a comma-separated list, or a path to a filename containing one feature name per line. See also the [security doc](/docs/en/writing-running-appium/security.md)|`--deny-insecure=foo,bar`|
+|`--log-filters`|null|Specify a full path to a JSON file containing one or more log filtering rules. This feature is useful for cases when it is necessary to obfuscate sensitive information, which may be present in server log records, like passwords or access tokens. The format of each rule is described in https://github.com/appium/appium-support/blob/master/lib/log-internal.js. An exception will be thrown on server startup if any of the rules has issues.|`--log-filters=/home/config.json`|

MODIFY
lib/main.js
lib/main.js
@@ -7,9 +7,12 @@ import _ from 'lodash';
import { server as baseServer, routeConfiguringFunction as makeRouter } from 'appium-base-driver';
import { asyncify } from 'asyncbox';
import { default as getParser, getDefaultArgs } from './parser';
-import { showConfig, checkNodeOk, validateServerArgs,
+import { logger as logFactory, util } from 'appium-support';
+import {
+ showConfig, checkNodeOk, validateServerArgs,
warnNodeDeprecations, validateTmpDir, getNonDefaultArgs,
- getDeprecatedArgs, getGitRev, APPIUM_VER } from './config';
+ getDeprecatedArgs, getGitRev, APPIUM_VER
+} from './config';
import { AppiumDriver } from './appium';
import registerNode from './grid-register';
import { inspectObject } from './utils';
@@ -111,6 +114,18 @@ async function main (args = null) {
args = parser.parseArgs();
}
await logsinkInit(args);
+ if (args.logFilters) {
+ const {issues, rules} = await logFactory.loadSecureValuesPreprocessingRules(args.logFilters);
+ if (!_.isEmpty(issues)) {
+ throw new Error(`The log filtering rules config '${args.logFilters}' has issues: ` +
+ JSON.stringify(issues, null, 2));
+ }
+ if (_.isEmpty(rules)) {
+ logger.warn(`Found no log filtering rules in '${args.logFilters}'. Is that expected?`);
+ } else {
+ logger.info(`Loaded ${util.pluralize('filtering rule', rules.length, true)} from '${args.logFilters}'`);
+ }
+ }
await preflightChecks(parser, args, throwInsteadOfExit);
await logStartupInfo(parser, args);
let appiumDriver = new AppiumDriver(args);

MODIFY
lib/parser.js
lib/parser.js
@@ -791,6 +791,14 @@ const deprecatedArgs = [
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - Port upon which ChromeDriver will run. If not given, Android driver will pick a random available port.',
}],
+
+ [['--log-filters'], {
+ dest: 'logFilters',
+ defaultValue: null,
+ required: false,
+ help: 'Set the full path to a JSON file containing one or more log filtering rules',
+ example: '/home/rules.json',
+ }],
];
function updateParseArgsForDefaultCapabilities (parser) {

feat: Add server command line option for logs filtering (#14239)