Repository: incubator-sentry Updated Branches: refs/heads/master f24db42b5 -> ac70d73c6
SENTRY-237: Support log4j configuration for Sentry service ( Arun Suresh via Sravya Tirukkovalur) Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/ac70d73c Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/ac70d73c Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/ac70d73c Branch: refs/heads/master Commit: ac70d73c6de06e2d912122770fae5a6e09fd1c8e Parents: f24db42 Author: Sravya Tirukkovalur <[email protected]> Authored: Mon Jun 2 20:05:58 2014 -0700 Committer: Sravya Tirukkovalur <[email protected]> Committed: Mon Jun 2 20:05:58 2014 -0700 ---------------------------------------------------------------------- sentry-core/sentry-core-common/pom.xml | 8 ++++++++ .../src/main/java/org/apache/sentry/SentryMain.java | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/ac70d73c/sentry-core/sentry-core-common/pom.xml ---------------------------------------------------------------------- diff --git a/sentry-core/sentry-core-common/pom.xml b/sentry-core/sentry-core-common/pom.xml index 84ab359..092fd30 100644 --- a/sentry-core/sentry-core-common/pom.xml +++ b/sentry-core/sentry-core-common/pom.xml @@ -37,6 +37,14 @@ limitations under the License. <artifactId>guava</artifactId> </dependency> <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </dependency> + <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/ac70d73c/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java ---------------------------------------------------------------------- diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java index c1ca6c5..58233e0 100644 --- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java +++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/SentryMain.java @@ -22,6 +22,9 @@ import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; +import org.apache.log4j.PropertyConfigurator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.common.collect.ImmutableMap; @@ -29,22 +32,32 @@ public class SentryMain { private static final String HELP_SHORT = "h"; private static final String HELP_LONG = "help"; private static final String COMMAND = "command"; + private static final String LOG4J_CONF = "log4jConf"; private static final ImmutableMap<String, String> COMMANDS = ImmutableMap .<String, String>builder() .put("service", "org.apache.sentry.service.thrift.SentryService$CommandImpl") .put("config-tool", "org.apache.sentry.binding.hive.authz.SentryConfigTool$CommandImpl") .put("schema-tool", "org.apache.sentry.provider.db.tools.SentrySchemaTool$CommandImpl") - .build(); + .build(); public static void main(String[] args) throws Exception { CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption(HELP_SHORT, HELP_LONG, false, "Print this help text"); options.addOption(null, COMMAND, true, "Command to run. Options: " + COMMANDS.keySet()); + options.addOption(null, LOG4J_CONF, true, "Location of log4j properties file"); //Ignore unrecognized options: service and config-tool options CommandLine commandLine = parser.parse(options, args, true); + String log4jconf = commandLine.getOptionValue(LOG4J_CONF); + if ((log4jconf != null)&&(log4jconf.length() > 0)) { + PropertyConfigurator.configure(log4jconf); + Logger sentryLogger = LoggerFactory.getLogger(SentryMain.class); + sentryLogger.info("Configuring log4j to use [" + log4jconf + "]"); + } + + //Print sentry help only if commandName was not given, // otherwise we assume the help is for the sub command String commandName = commandLine.getOptionValue(COMMAND);
