You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2021/12/13 21:07:24 UTC
[jackrabbit-filevault] branch master updated: JCRVLT-573 use logback instead of the ancient log4j 1.2 (#185)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git
The following commit(s) were added to refs/heads/master by this push:
new 83ed959 JCRVLT-573 use logback instead of the ancient log4j 1.2 (#185)
83ed959 is described below
commit 83ed959f8fc991afeb14c8abdbe64b8b64dfc4e2
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon Dec 13 22:06:06 2021 +0100
JCRVLT-573 use logback instead of the ancient log4j 1.2 (#185)
---
src/site/markdown/usage.md | 21 ++++++----
vault-cli/pom.xml | 16 +++-----
vault-cli/src/main/appassembler/unix-template.sh | 8 ++--
.../src/main/appassembler/windows-template.bat | 8 ++--
vault-cli/src/main/assembly/assembly.xml | 4 ++
vault-cli/src/main/config/logback.xml | 32 +++++++++++++++
.../apache/jackrabbit/vault/cli/VaultFsApp.java | 10 -----
.../vault/util/console/AbstractApplication.java | 32 +++++++--------
.../vault/util/console/util/Log4JConfig.java | 47 ----------------------
.../apache/jackrabbit/vault/cli/log4j.properties | 26 ------------
.../jackrabbit/vault/util/console/log4j.properties | 26 ------------
11 files changed, 77 insertions(+), 153 deletions(-)
diff --git a/src/site/markdown/usage.md b/src/site/markdown/usage.md
index 1b3aefa..81aabaa 100644
--- a/src/site/markdown/usage.md
+++ b/src/site/markdown/usage.md
@@ -29,12 +29,12 @@ The console tool is called `vlt` and has the following usage:
$vlt --help
- ----------------------------------------------------------------------------------------------------------------------------------
- Jackrabbit FileVault [version 3.4.5] copyright 2013-2020 by Apache Software Foundation. See LICENSE.txt for more information.
- ----------------------------------------------------------------------------------------------------------------------------------
+ ----------------------------------------------------------------------------------------------------------------------------------------
+ Jackrabbit FileVault [version 3.5.7-SNAPSHOT] copyright 2013-2021 by Apache Software Foundation. See LICENSE.txt for more information.
+ ----------------------------------------------------------------------------------------------------------------------------------------
Usage:
vlt [options] <command> [arg1 [arg2 [arg3] ..]]
- ----------------------------------------------------------------------------------------------------------------------------------
+ ----------------------------------------------------------------------------------------------------------------------------------------
Global options:
-Xjcrlog <arg> Extended JcrLog options (omit argument for help)
@@ -50,14 +50,13 @@ The console tool is called `vlt` and has the following usage:
--socketTimeoutMs <arg> The socket timeout in milliseconds.
--proxyHost <arg> The host of the proxy to use.
--proxyPort <arg> The port where the proxy is running (requires proxyHost as well).
- --proxyProtocol <arg> The protocol for which to use the proxy (requires proxyHost as well). If not set proxy is used
- for both HTTP and HTTPS.
+ --proxyProtocol <arg> The protocol for which to use the proxy (requires proxyHost as well). If not set proxy is used for both HTTP and HTTPS.
--proxyUsername <arg> The username to use for authentication at the proxy (requires proxyHost as well).
--proxyPassword <arg> The password to use for authentication at the proxy (requires proxyUsername as well)
-v (--verbose) verbose output
-q (--quiet) print as little as possible
--version print the version information and exit
- --log-level <level> the log4j log level
+ --log-level <level> the logback log level
-h (--help) <command> print this help
Commands:
export Export the Vault filesystem
@@ -79,7 +78,7 @@ The console tool is called `vlt` and has the following usage:
sync Control vault sync service
format Formats vault docview files.
console Run an interactive console
- ----------------------------------------------------------------------------------------------------------------------------------
+ ----------------------------------------------------------------------------------------------------------------------------------------
Checkout
@@ -94,6 +93,12 @@ Adding / Removing Files
-----------------------
_todo_
+Logging
+---------
+`vlt` uses [logback](http://logback.qos.ch/) for logging. To adjust the logging configuration you can either use the
+cli option `--log-level <level>` or edit the [logback xml configuration](http://logback.qos.ch/manual/configuration.html)
+at `etc/logback.xml` for more granular settings.
+
Vault Sync
----------
The vault sync service is used to synchronize repository content with a local filesystem representation and vice versa.
diff --git a/vault-cli/pom.xml b/vault-cli/pom.xml
index 7f087bf..37eeac9 100644
--- a/vault-cli/pom.xml
+++ b/vault-cli/pom.xml
@@ -61,7 +61,8 @@
<windowsScriptTemplate>${basedir}/src/main/appassembler/windows-template.bat</windowsScriptTemplate>
<repositoryLayout>flat</repositoryLayout>
<repositoryName>lib</repositoryName>
- <includeConfigurationDirectoryInClasspath>false</includeConfigurationDirectoryInClasspath>
+ <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
+ <copyConfigurationDirectory>true</copyConfigurationDirectory>
<extraJvmArguments>-Xms500m -Xmx500m</extraJvmArguments>
<programs>
<program>
@@ -162,21 +163,16 @@
<scope>compile</scope>
</dependency>
- <!-- SLF4j / Log4j -->
+ <!-- SLF4j / Logback -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <scope>compile</scope>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>1.2.6</version>
</dependency>
</dependencies>
</project>
diff --git a/vault-cli/src/main/appassembler/unix-template.sh b/vault-cli/src/main/appassembler/unix-template.sh
index 4ff0ec2..c8db85a 100644
--- a/vault-cli/src/main/appassembler/unix-template.sh
+++ b/vault-cli/src/main/appassembler/unix-template.sh
@@ -41,7 +41,7 @@ while [ -h "$PRG" ]; do
done
PRGDIR=`dirname "$PRG"`
-VLT_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`
+BASEDIR=`cd "$PRGDIR/.." >/dev/null; pwd`
@ENV_SETUP@
@@ -97,7 +97,7 @@ fi
if [ -z "$REPO" ]
then
- REPO="$VLT_HOME"/@REPO@
+ REPO="$BASEDIR"/@REPO@
fi
CLASSPATH=$CLASSPATH_PREFIX:@CLASSPATH@
@@ -107,7 +107,7 @@ if $cygwin; then
[ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$HOME" ] && HOME=`cygpath --path --windows "$HOME"`
- [ -n "$VLT_HOME" ] && VLT_HOME=`cygpath --path --windows "$VLT_HOME"`
+ [ -n "$BASEDIR" ] && BASEDIR=`cygpath --path --windows "$BASEDIR"`
[ -n "$REPO" ] && REPO=`cygpath --path --windows "$REPO"`
fi
@@ -131,6 +131,6 @@ exec "$JAVACMD" $VLT_OPTS $EXTRA_JVM_ARGUMENTS \
-Dapp.name="@APP_NAME@" \
-Dapp.pid="$$" \
-Dapp.repo="$REPO" \
- -Dvlt.home="$VLT_HOME" \
+ -Dvlt.home="$BASEDIR" \
@MAINCLASS@ \
@APP_ARGUMENTS@"$@"@UNIX_BACKGROUND@
diff --git a/vault-cli/src/main/appassembler/windows-template.bat b/vault-cli/src/main/appassembler/windows-template.bat
index 3666be3..69ec23a 100644
--- a/vault-cli/src/main/appassembler/windows-template.bat
+++ b/vault-cli/src/main/appassembler/windows-template.bat
@@ -66,20 +66,20 @@ goto Win9xApp
set SAVEDIR=%CD%
%0\
cd %0\..\..
-set VLT_HOME=%CD%
+set BASEDIR=%CD%
cd %SAVEDIR%
set SAVE_DIR=
goto repoSetup
:WinNTGetScriptDir
-set VLT_HOME=%~dp0\..
+set BASEDIR=%~dp0\..
:repoSetup
#ENV_SETUP#
if "%JAVACMD%"=="" set JAVACMD=#JAVA_BINARY#
-if "%REPO%"=="" set REPO=%VLT_HOME%\#REPO#
+if "%REPO%"=="" set REPO=%BASEDIR%\#REPO#
set CLASSPATH=#CLASSPATH#
goto endInit
@@ -87,7 +87,7 @@ goto endInit
@REM Reaching here means variables are defined and arguments have been captured
:endInit
-%JAVACMD% %VLT_OPTS% #EXTRA_JVM_ARGUMENTS# -classpath %CLASSPATH_PREFIX%;%CLASSPATH% -Dapp.name="#APP_NAME#" -Dapp.repo="%REPO%" -Dapp.home="%VLT_HOME%" -Dvlt.home="%VLT_HOME%" #MAINCLASS# #APP_ARGUMENTS#%CMD_LINE_ARGS%
+%JAVACMD% %VLT_OPTS% #EXTRA_JVM_ARGUMENTS# -classpath %CLASSPATH_PREFIX%;%CLASSPATH% -Dapp.name="#APP_NAME#" -Dapp.repo="%REPO%" -Dapp.home="%BASEDIR%" -Dvlt.home="%BASEDIR%" #MAINCLASS# #APP_ARGUMENTS#%CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end
diff --git a/vault-cli/src/main/assembly/assembly.xml b/vault-cli/src/main/assembly/assembly.xml
index 62a4e0b..023d0dd 100644
--- a/vault-cli/src/main/assembly/assembly.xml
+++ b/vault-cli/src/main/assembly/assembly.xml
@@ -47,5 +47,9 @@
<directory>${project.build.directory}/appassembler/lib/</directory>
<outputDirectory>/lib</outputDirectory>
</fileSet>
+ <fileSet>
+ <directory>${project.build.directory}/appassembler/etc/</directory>
+ <outputDirectory>/etc</outputDirectory>
+ </fileSet>
</fileSets>
</assembly>
diff --git a/vault-cli/src/main/config/logback.xml b/vault-cli/src/main/config/logback.xml
new file mode 100644
index 0000000..22efc0b
--- /dev/null
+++ b/vault-cli/src/main/config/logback.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<configuration packagingData="true">
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>[%-5level] %msg%n</pattern>
+ <!-- more verbose pattern example: %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n -->
+ </encoder>
+ </appender>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
\ No newline at end of file
diff --git a/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/VaultFsApp.java b/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/VaultFsApp.java
index ff74af8..706f987 100644
--- a/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/VaultFsApp.java
+++ b/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/VaultFsApp.java
@@ -56,7 +56,6 @@ import org.apache.jackrabbit.vault.util.console.ExecutionContext;
import org.apache.jackrabbit.vault.util.console.ExecutionException;
import org.apache.jackrabbit.vault.util.console.commands.CmdConsole;
import org.apache.jackrabbit.vault.util.console.util.CliHelpFormatter;
-import org.apache.jackrabbit.vault.util.console.util.Log4JConfig;
import org.apache.jackrabbit.vault.util.console.util.PomProperties;
import org.apache.jackrabbit.vault.vlt.ConfigCredentialsStore;
import org.apache.jackrabbit.vault.vlt.CredentialsStore;
@@ -72,8 +71,6 @@ import org.slf4j.LoggerFactory;
*/
public class VaultFsApp extends AbstractApplication {
- private static final String LOG4J_PROPERTIES = "/org/apache/jackrabbit/vault/cli/log4j.properties";
-
public static final String KEY_URI = "uri";
public static final String KEY_WORKSPACE = "workspace";
public static final String KEY_MOUNTPOINT = "mountpoint";
@@ -459,13 +456,6 @@ public class VaultFsApp extends AbstractApplication {
/**
* {@inheritDoc}
*/
- protected void initLogging() {
- Log4JConfig.init(LOG4J_PROPERTIES);
- }
-
- /**
- * {@inheritDoc}
- */
protected void init() {
super.init();
initLineSeparator();
diff --git a/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java b/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java
index a1731b8..15b6404 100644
--- a/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java
+++ b/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java
@@ -36,11 +36,13 @@ import org.apache.commons.cli2.commandline.Parser;
import org.apache.commons.cli2.option.Command;
import org.apache.commons.cli2.util.HelpFormatter;
import org.apache.jackrabbit.vault.util.console.util.CliHelpFormatter;
-import org.apache.jackrabbit.vault.util.console.util.Log4JConfig;
import org.apache.jackrabbit.vault.util.console.util.PomProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.LoggerContext;
+
/**
* {@code Console}...
*/
@@ -51,8 +53,6 @@ public abstract class AbstractApplication {
*/
static final Logger log = LoggerFactory.getLogger(AbstractApplication.class);
- private static final String LOG4J_PROPERTIES = "/org/apache/jackrabbit/vault/util/console/log4j.properties";
-
public static final String DEFAULT_CONF_FILENAME = "console.properties";
public static final String KEY_PROMPT = "prompt";
@@ -191,7 +191,7 @@ public abstract class AbstractApplication {
optLogLevel =
obuilder
.withLongName("log-level")
- .withDescription("the log4j log level")
+ .withDescription("the logback log level")
.withArgument(abuilder
.withName("level")
.withMaximum(1)
@@ -221,18 +221,7 @@ public abstract class AbstractApplication {
"[${" + KEY_USER + "}@${" + KEY_HOST + "} ${" + KEY_PATH +"}]$ ");
}
- protected void initLogging() {
- Log4JConfig.init(LOG4J_PROPERTIES);
- }
-
protected void run(String[] args) {
- // setup logging
- try {
- initLogging();
- } catch (Throwable e) {
- System.err.println("Error while initializing logging: " + e);
- }
-
// setup and start
init();
@@ -246,7 +235,10 @@ public abstract class AbstractApplication {
logLevel = (String) cl.getValue(optLogLevel);
}
if (logLevel != null) {
- Log4JConfig.setLevel(logLevel);
+ LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
+ // overwrite level of configuration file
+ ch.qos.logback.classic.Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
+ rootLogger.setLevel(Level.toLevel(logLevel));
}
prepare(cl);
execute(cl);
@@ -261,9 +253,13 @@ public abstract class AbstractApplication {
public void setLogLevel(String level) {
try {
- Log4JConfig.setLevel(level);
+ LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
+ // overwrite level of configuration file
+ ch.qos.logback.classic.Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
+ Level logLevel = Level.toLevel(level);
+ rootLogger.setLevel(Level.toLevel(level));
getEnv().setProperty(KEY_LOGLEVEL, level);
- System.out.println("Log level set to '" + Log4JConfig.getLevel() + "'");
+ System.out.println("Log level set to '" + logLevel + "'");
} catch (Throwable e) {
System.err.println("Error while setting log level: " + e);
}
diff --git a/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Log4JConfig.java b/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Log4JConfig.java
deleted file mode 100644
index 69210a7..0000000
--- a/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Log4JConfig.java
+++ /dev/null
@@ -1,47 +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.
- */
-package org.apache.jackrabbit.vault.util.console.util;
-
-import java.net.URL;
-
-import org.apache.jackrabbit.vault.util.console.ExecutionException;
-import org.apache.log4j.Level;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.PropertyConfigurator;
-
-/**
- * {@code Log4JConfig}...
- */
-public class Log4JConfig {
-
- public static void init(String log4jConfig) {
- URL url = Log4JConfig.class.getResource(log4jConfig);
- PropertyConfigurator.configure(url);
- }
-
- public static void setLevel(String level) {
- Level l = Level.toLevel(level);
- if (l == null) {
- throw new ExecutionException("Invalid log level " + level);
- }
- LogManager.getRootLogger().setLevel(l);
- }
-
- public static String getLevel() {
- return LogManager.getRootLogger().getLevel().toString();
- }
-}
\ No newline at end of file
diff --git a/vault-cli/src/main/resources/org/apache/jackrabbit/vault/cli/log4j.properties b/vault-cli/src/main/resources/org/apache/jackrabbit/vault/cli/log4j.properties
deleted file mode 100644
index 2675c06..0000000
--- a/vault-cli/src/main/resources/org/apache/jackrabbit/vault/cli/log4j.properties
+++ /dev/null
@@ -1,26 +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.
-#
-
-# Set root logger level to WARN and its only appender to A1.
-log4j.rootLogger=WARN, A1
-
-# A1 is set to be a ConsoleAppender.
-log4j.appender.A1=org.apache.log4j.ConsoleAppender
-
-# A1 uses PatternLayout.
-log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=[%-5p] %m%n
diff --git a/vault-cli/src/main/resources/org/apache/jackrabbit/vault/util/console/log4j.properties b/vault-cli/src/main/resources/org/apache/jackrabbit/vault/util/console/log4j.properties
deleted file mode 100644
index cda0c8b..0000000
--- a/vault-cli/src/main/resources/org/apache/jackrabbit/vault/util/console/log4j.properties
+++ /dev/null
@@ -1,26 +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.
-#
-
-# Set root logger level to INFO and its only appender to A1.
-log4j.rootLogger=INFO, A1
-
-# A1 is set to be a ConsoleAppender.
-log4j.appender.A1=org.apache.log4j.ConsoleAppender
-
-# A1 uses PatternLayout.
-log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=[%-5p] %m%n