From ef6f0238ef5dbb439e85ee3c8988319c375e65df Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Wed, 10 Feb 2010 19:53:56 +0000 Subject: [PATCH] finish r/m of -f option. use log4j of WARN,stderr so that doesn't get in the way of redirecting stdout. patch by jbellis; reviewed by eevans for CASSANDRA-766 git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@908652 13f79535-47bb-0310-9956-ffa450edef68 --- bin/clustertool | 4 +- bin/json2sstable | 1 + bin/nodetool | 1 + bin/sstable2json | 1 + bin/sstablekeys | 1 + conf/log4j-tools.properties | 27 ++++++++++++ .../apache/cassandra/tools/SSTableExport.java | 41 ++++--------------- 7 files changed, 43 insertions(+), 33 deletions(-) create mode 100644 conf/log4j-tools.properties diff --git a/bin/clustertool b/bin/clustertool index ec57e254d9..0dbfd02d6f 100755 --- a/bin/clustertool +++ b/bin/clustertool @@ -50,6 +50,8 @@ case "`uname`" in ;; esac -$JAVA -cp $CLASSPATH org.apache.cassandra.tools.ClusterCmd $@ +$JAVA -cp $CLASSPATH \ + -Dlog4j.configuration=log4j-tools.properties \ + org.apache.cassandra.tools.ClusterCmd $@ # vi:ai sw=4 ts=4 tw=0 et diff --git a/bin/json2sstable b/bin/json2sstable index df46e0fd8c..02ebaaff6b 100755 --- a/bin/json2sstable +++ b/bin/json2sstable @@ -44,6 +44,7 @@ if [ -z $CLASSPATH ]; then fi $JAVA -cp $CLASSPATH -Dstorage-config=$CASSANDRA_CONF \ + -Dlog4j.configuration=log4j-tools.properties \ org.apache.cassandra.tools.SSTableImport "$@" # vi:ai sw=4 ts=4 tw=0 et diff --git a/bin/nodetool b/bin/nodetool index f0b8c2002e..6410bfb136 100755 --- a/bin/nodetool +++ b/bin/nodetool @@ -56,6 +56,7 @@ case "`uname`" in esac $JAVA -cp $CLASSPATH -Dstorage-config=$CASSANDRA_CONF \ + -Dlog4j.configuration=log4j-tools.properties \ org.apache.cassandra.tools.NodeCmd $@ # vi:ai sw=4 ts=4 tw=0 et diff --git a/bin/sstable2json b/bin/sstable2json index c8a70dd0e2..dca2bd639b 100755 --- a/bin/sstable2json +++ b/bin/sstable2json @@ -45,6 +45,7 @@ if [ -z $CLASSPATH ]; then fi $JAVA -cp $CLASSPATH -Dstorage-config=$CASSANDRA_CONF \ + -Dlog4j.configuration=log4j-tools.properties \ org.apache.cassandra.tools.SSTableExport "$@" # vi:ai sw=4 ts=4 tw=0 et diff --git a/bin/sstablekeys b/bin/sstablekeys index ab4c121c37..3c2aa332af 100755 --- a/bin/sstablekeys +++ b/bin/sstablekeys @@ -49,6 +49,7 @@ if [ $# -eq "0" ]; then fi $JAVA -cp $CLASSPATH -Dstorage-config=$CASSANDRA_CONF \ + -Dlog4j.configuration=log4j-tools.properties \ org.apache.cassandra.tools.SSTableExport "$1" -e # vi:ai sw=4 ts=4 tw=0 et diff --git a/conf/log4j-tools.properties b/conf/log4j-tools.properties new file mode 100644 index 0000000000..a8f4d9f05b --- /dev/null +++ b/conf/log4j-tools.properties @@ -0,0 +1,27 @@ +# 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. + +# for production, you should probably set the root to INFO +# and the pattern to %c instead of %l. (%l is slower.) + +# output messages into a rolling log file as well as stdout +log4j.rootLogger=WARN,stderr + +# stderr +log4j.appender.stderr=org.apache.log4j.ConsoleAppender +log4j.appender.stderr.target=System.err +log4j.appender.stderr.layout=org.apache.log4j.PatternLayout +log4j.appender.stderr.layout.ConversionPattern=%5p %d{HH:mm:ss,SSS} %m%n diff --git a/src/java/org/apache/cassandra/tools/SSTableExport.java b/src/java/org/apache/cassandra/tools/SSTableExport.java index 08369c0728..b9495e0250 100644 --- a/src/java/org/apache/cassandra/tools/SSTableExport.java +++ b/src/java/org/apache/cassandra/tools/SSTableExport.java @@ -46,7 +46,6 @@ public class SSTableExport { private static int INPUT_FILE_BUFFER_SIZE = 8 * 1024 * 1024; - private static final String OUTFILE_OPTION = "f"; private static final String KEY_OPTION = "k"; private static final String ENUMERATEKEYS_OPTION = "e"; private static Options options; @@ -55,19 +54,13 @@ public class SSTableExport static { options = new Options(); - Option optOutfile = new Option(OUTFILE_OPTION, true, "output file"); - optOutfile.setRequired(false); - options.addOption(optOutfile); - + Option optKey = new Option(KEY_OPTION, true, "Row key"); // Number of times -k can be passed on the command line. optKey.setArgs(500); - optKey.setRequired(false); options.addOption(optKey); - options = new Options(); Option optEnumerate = new Option(ENUMERATEKEYS_OPTION, false, "enumerate keys only"); - optOutfile.setRequired(false); options.addOption(optEnumerate); } @@ -327,8 +320,7 @@ public class SSTableExport */ public static void main(String[] args) throws IOException { - String usage = String.format("Usage: %s [-f outfile] [-k key [-k key [...]]]%n", - SSTableExport.class.getName()); + String usage = String.format("Usage: %s [-k key [-k key [...]]]%n", SSTableExport.class.getName()); CommandLineParser parser = new PosixParser(); try @@ -341,7 +333,6 @@ public class SSTableExport System.exit(1); } - String outFile = cmd.getOptionValue(OUTFILE_OPTION); if (cmd.getArgs().length != 1) { @@ -354,27 +345,13 @@ public class SSTableExport String[] keys = cmd.getOptionValues(KEY_OPTION); String ssTableFileName = new File(cmd.getArgs()[0]).getAbsolutePath(); - if (outFile != null) - { - if (cmd.hasOption(ENUMERATEKEYS_OPTION)) - enumeratekeys(ssTableFileName, outFile); - else { - if ((keys != null) && (keys.length > 0)) - export(ssTableFileName, outFile, keys); - else - export(ssTableFileName, outFile); - } - } - else - { - if (cmd.hasOption(ENUMERATEKEYS_OPTION)) - enumeratekeys(ssTableFileName, System.out); - else { - if ((keys != null) && (keys.length > 0)) - export(ssTableFileName, System.out, keys); - else - export(ssTableFileName); - } + if (cmd.hasOption(ENUMERATEKEYS_OPTION)) + enumeratekeys(ssTableFileName, System.out); + else { + if ((keys != null) && (keys.length > 0)) + export(ssTableFileName, System.out, keys); + else + export(ssTableFileName); } System.exit(0); }