From fa13832a9c07b20e968efc5d8baf7e7e09e1a7b1 Mon Sep 17 00:00:00 2001 From: Jeff Storck Date: Wed, 16 Nov 2016 17:41:12 -0500 Subject: [PATCH] NIFI-3049 Fixes logging issues due to logback and log4j being on the classpath Removed logback usage from classpath Added slf4j-log4j12 dependency in nifi-toolkit pom Added logback-classic exclusion for nifi-properties-loader used by nifi-toolkit-encrypt-config Updated log4j.properties logging pattern and logger config in nifi-toolkit-assembly and nifi-toolkit-zookeeper-migrator, filtering zookeeper messages below WARN Removed logback.groovy since log4j is the single logging implementation Updated ZooKeeperMigratorMain command line output to match standards established by other tools in nifi-toolkit This closes #1237. Signed-off-by: Andy LoPresto --- .../main/resources/classpath/log4j.properties | 4 +- .../main/resources/classpath/logback.groovy | 39 ------------------ .../nifi-toolkit-encrypt-config/pom.xml | 6 +++ .../nifi-toolkit-zookeeper-migrator/pom.xml | 40 +++++++------------ .../zkmigrator/ZooKeeperMigratorMain.java | 13 ++++-- .../src/test/resources/log4j.properties | 24 +++++++++++ .../src/test/resources/logback.groovy | 39 ------------------ nifi-toolkit/pom.xml | 6 +++ 8 files changed, 63 insertions(+), 108 deletions(-) delete mode 100644 nifi-toolkit/nifi-toolkit-assembly/src/main/resources/classpath/logback.groovy create mode 100644 nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/test/resources/log4j.properties delete mode 100644 nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/test/resources/logback.groovy diff --git a/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/classpath/log4j.properties b/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/classpath/log4j.properties index fc2aaf12c4..6072b3e3ec 100644 --- a/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/classpath/log4j.properties +++ b/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/classpath/log4j.properties @@ -17,6 +17,8 @@ log4j.rootLogger=INFO,console +log4j.logger.org.apache.zookeeper=WARN,console + log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n \ No newline at end of file +log4j.appender.console.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %p [%t] %c: %m%n \ No newline at end of file diff --git a/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/classpath/logback.groovy b/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/classpath/logback.groovy deleted file mode 100644 index ac77f24b84..0000000000 --- a/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/classpath/logback.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import ch.qos.logback.classic.encoder.PatternLayoutEncoder -import ch.qos.logback.core.ConsoleAppender -import ch.qos.logback.core.status.NopStatusListener - -statusListener(NopStatusListener) - -appender('stdout', ConsoleAppender) { - target = 'System.out' - encoder(PatternLayoutEncoder) { - pattern = "%date %level [%thread] %logger{40} %msg%n" - } -} - -appender('stderr', ConsoleAppender) { - target = 'System.err' - encoder(PatternLayoutEncoder) { - pattern = "%date %level [%thread] %logger{40} %msg%n" - } -} - -logger("org.apache.nifi.toolkit.zkmigrator", INFO) -logger("org.apache.zookeeper", WARN) -root(WARN, ['stderr']) diff --git a/nifi-toolkit/nifi-toolkit-encrypt-config/pom.xml b/nifi-toolkit/nifi-toolkit-encrypt-config/pom.xml index 977c8b1d20..3b094c7cea 100644 --- a/nifi-toolkit/nifi-toolkit-encrypt-config/pom.xml +++ b/nifi-toolkit/nifi-toolkit-encrypt-config/pom.xml @@ -31,6 +31,12 @@ org.apache.nifi nifi-properties-loader + + + ch.qos.logback + logback-classic + + org.apache.nifi diff --git a/nifi-toolkit/nifi-toolkit-zookeeper-migrator/pom.xml b/nifi-toolkit/nifi-toolkit-zookeeper-migrator/pom.xml index 536fbce4ec..0273dd77f9 100644 --- a/nifi-toolkit/nifi-toolkit-zookeeper-migrator/pom.xml +++ b/nifi-toolkit/nifi-toolkit-zookeeper-migrator/pom.xml @@ -39,40 +39,28 @@ org.slf4j slf4j-api - - ch.qos.logback - logback-classic - compile - org.apache.zookeeper zookeeper - - - - - - - - - - - - - - - + + + log4j + log4j + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + com.google.code.gson gson - - - org.codehaus.groovy - groovy-all - org.spockframework spock-core diff --git a/nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/main/java/org/apache/nifi/toolkit/zkmigrator/ZooKeeperMigratorMain.java b/nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/main/java/org/apache/nifi/toolkit/zkmigrator/ZooKeeperMigratorMain.java index bf037a03ad..c8488a1196 100644 --- a/nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/main/java/org/apache/nifi/toolkit/zkmigrator/ZooKeeperMigratorMain.java +++ b/nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/main/java/org/apache/nifi/toolkit/zkmigrator/ZooKeeperMigratorMain.java @@ -37,13 +37,19 @@ public class ZooKeeperMigratorMain { enum Mode {READ, WRITE} + private static final String JAVA_HOME = "JAVA_HOME"; + private static final String NIFI_TOOLKIT_HOME = "NIFI_TOOLKIT_HOME"; + private static final String HEADER = System.lineSeparator() + "A tool for importing and exporting data from ZooKeeper." + System.lineSeparator() + System.lineSeparator(); + private static final String FOOTER = new StringBuilder(System.lineSeparator()).append("Java home: ") + .append(System.getenv(JAVA_HOME)).append(System.lineSeparator()).append("NiFi Toolkit home: ").append(System.getenv(NIFI_TOOLKIT_HOME)).toString(); + private static final Option OPTION_ZK_MIGRATOR_HELP = Option.builder("h") .longOpt("help") .desc("display help/usage info") .build(); private static final Option OPTION_ZK_ENDPOINT = Option.builder("z") .longOpt("zookeeper") - .desc("ZooKeeper connect string with path (ex. host:port/path)") + .desc("ZooKeeper endpoint string (ex. host:port/path)") .hasArg() .argName("zookeeper-endpoint") .required() @@ -95,11 +101,12 @@ public class ZooKeeperMigratorMain { private static void printUsage(String errorMessage, Options options) { Preconditions.checkNotNull(options, "command line options were not specified"); if (errorMessage != null) { - System.out.println(String.format("%s\n", errorMessage)); + System.out.println(errorMessage + System.lineSeparator()); } HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setWidth(160); - helpFormatter.printHelp(ZooKeeperMigratorMain.class.getCanonicalName(), options, true); + helpFormatter.setDescPadding(0); + helpFormatter.printHelp(ZooKeeperMigratorMain.class.getCanonicalName(), HEADER, options, FOOTER, true); } public static void main(String[] args) { diff --git a/nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/test/resources/log4j.properties b/nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/test/resources/log4j.properties new file mode 100644 index 0000000000..6072b3e3ec --- /dev/null +++ b/nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/test/resources/log4j.properties @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +log4j.rootLogger=INFO,console + +log4j.logger.org.apache.zookeeper=WARN,console + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %p [%t] %c: %m%n \ No newline at end of file diff --git a/nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/test/resources/logback.groovy b/nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/test/resources/logback.groovy deleted file mode 100644 index ac77f24b84..0000000000 --- a/nifi-toolkit/nifi-toolkit-zookeeper-migrator/src/test/resources/logback.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import ch.qos.logback.classic.encoder.PatternLayoutEncoder -import ch.qos.logback.core.ConsoleAppender -import ch.qos.logback.core.status.NopStatusListener - -statusListener(NopStatusListener) - -appender('stdout', ConsoleAppender) { - target = 'System.out' - encoder(PatternLayoutEncoder) { - pattern = "%date %level [%thread] %logger{40} %msg%n" - } -} - -appender('stderr', ConsoleAppender) { - target = 'System.err' - encoder(PatternLayoutEncoder) { - pattern = "%date %level [%thread] %logger{40} %msg%n" - } -} - -logger("org.apache.nifi.toolkit.zkmigrator", INFO) -logger("org.apache.zookeeper", WARN) -root(WARN, ['stderr']) diff --git a/nifi-toolkit/pom.xml b/nifi-toolkit/pom.xml index a898fe7518..fe8fafa941 100644 --- a/nifi-toolkit/pom.xml +++ b/nifi-toolkit/pom.xml @@ -45,4 +45,10 @@ + + + org.slf4j + slf4j-log4j12 + +