From 7e6572d60bbf7f236072e0bd15593f7af776b3f1 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 23 May 2011 08:38:02 +0200 Subject: [PATCH] remove logback loading messages --- .../src/main/java/sonia/scm/cli/App.java | 24 ++++ .../src/main/java/sonia/scm/cli/I18n.java | 3 + .../scm/cli/LoggingLevelOptionHandler.java | 104 ++++++++++++++++++ .../src/main/resources/logback.xml | 27 ----- .../resources/sonia/resources/i18n.properties | 2 + 5 files changed, 133 insertions(+), 27 deletions(-) create mode 100644 scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/LoggingLevelOptionHandler.java delete mode 100644 scm-clients/scm-cli-client/src/main/resources/logback.xml diff --git a/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/App.java b/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/App.java index 1975071805..ca8737101c 100644 --- a/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/App.java +++ b/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/App.java @@ -35,6 +35,9 @@ package sonia.scm.cli; //~--- non-JDK imports -------------------------------------------------------- +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.LoggerContext; + import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.CmdLineParser; @@ -146,6 +149,7 @@ public class App System.exit(1); } + configureLogger(); loadConfig(); I18n i18n = new I18n(); @@ -164,6 +168,17 @@ public class App IOUtil.close(output); } + /** + * Method description + * + */ + private void configureLogger() + { + LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); + + lc.getLogger(Logger.ROOT_LOGGER_NAME).setLevel(loggingLevel); + } + /** * Method description * @@ -278,6 +293,15 @@ public class App /** Field description */ private BufferedReader input; + /** Field description */ + @Option( + name = "--logging-level", + usage = "optionLoggingLevel", + handler = LoggingLevelOptionHandler.class, + aliases = { "-l" } + ) + private Level loggingLevel = Level.ERROR; + /** Field description */ private PrintWriter output; diff --git a/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/I18n.java b/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/I18n.java index a35bba73dd..8ee1e597e3 100644 --- a/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/I18n.java +++ b/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/I18n.java @@ -56,6 +56,9 @@ public class I18n /** Field description */ public static final String GROUP_NOT_FOUND = "groupNotFound"; + /** Field description */ + public static final String LEVEL = "level"; + /** Field description */ public static final String OPTIONS = "options"; diff --git a/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/LoggingLevelOptionHandler.java b/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/LoggingLevelOptionHandler.java new file mode 100644 index 0000000000..2622abecfb --- /dev/null +++ b/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/LoggingLevelOptionHandler.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of SCM-Manager; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.cli; + +//~--- non-JDK imports -------------------------------------------------------- + +import ch.qos.logback.classic.Level; + +import org.kohsuke.args4j.CmdLineException; +import org.kohsuke.args4j.CmdLineParser; +import org.kohsuke.args4j.OptionDef; +import org.kohsuke.args4j.spi.OptionHandler; +import org.kohsuke.args4j.spi.Parameters; +import org.kohsuke.args4j.spi.Setter; + +/** + * + * @author Sebastian Sdorra + */ +public class LoggingLevelOptionHandler extends OptionHandler +{ + + /** + * Constructs ... + * + * + * @param parser + * @param option + * @param setter + */ + public LoggingLevelOptionHandler(CmdLineParser parser, OptionDef option, + Setter setter) + { + super(parser, option, setter); + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param params + * + * @return + * + * @throws CmdLineException + */ + @Override + public int parseArguments(Parameters params) throws CmdLineException + { + String value = params.getParameter(0); + Level l = Level.toLevel(value); + + setter.addValue(l); + + return 1; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + public String getDefaultMetaVariable() + { + return I18n.LEVEL; + } +} diff --git a/scm-clients/scm-cli-client/src/main/resources/logback.xml b/scm-clients/scm-cli-client/src/main/resources/logback.xml deleted file mode 100644 index 3af702a1e5..0000000000 --- a/scm-clients/scm-cli-client/src/main/resources/logback.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n - - - - - - - - - - \ No newline at end of file diff --git a/scm-clients/scm-cli-client/src/main/resources/sonia/resources/i18n.properties b/scm-clients/scm-cli-client/src/main/resources/sonia/resources/i18n.properties index 1221c7e996..002e183fcb 100644 --- a/scm-clients/scm-cli-client/src/main/resources/sonia/resources/i18n.properties +++ b/scm-clients/scm-cli-client/src/main/resources/sonia/resources/i18n.properties @@ -38,6 +38,7 @@ optionServerUrl = SCM-Manager URL optionUsername = Username optionPassword = Password optionHelpText = Shows this help +optionLoggingLevel = Logging level (DEBUG, INFO, WARN, ERROR) optionTemplate = Template optionTemplateFile = Template file optionRepositoryId = Repository Id @@ -80,6 +81,7 @@ misc = Miscellaneous repository = Repository group = Group user = User +level = Logging-Level options = Options usage = scm-cli-client [options] command [command options]