[java-identity-provider] 03/03: JSE-40 Make logging levels work on command lines

Rod Widdowson rdw at steadingsoftware.com
Mon Sep 7 10:35:29 UTC 2020


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=6ddfec3b1121110736bbd98d0554a520b3aebd93

commit 6ddfec3b1121110736bbd98d0554a520b3aebd93
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Sep 7 11:22:08 2020 +0100

    JSE-40 Make logging levels work on command lines
    
    https://issues.shibboleth.net/jira/browse/JSE-40
    
    The Log has to be lazy-constructed so as to happen after
    we have forced the log source.
---
 .../idp/module/impl/ModuleManagerArguments.java    | 14 +++++++---
 .../shibboleth/idp/cli/DataSealerArguments.java    | 17 ++++++++++--
 .../installer/plugin/PluginInstallerArguments.java | 32 ++++++++++++++--------
 .../idp/installer/plugin/PluginInstallerCLI.java   |  4 +--
 4 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerArguments.java b/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerArguments.java
index d18b4e0b2..f58d30ca7 100644
--- a/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerArguments.java
+++ b/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerArguments.java
@@ -22,7 +22,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.apache.http.client.HttpClient;
@@ -45,7 +44,7 @@ import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
 public class ModuleManagerArguments extends AbstractIdPHomeAwareCommandLineArguments {
 
     /** Logger. */
-    @Nonnull private final Logger log = LoggerFactory.getLogger(ModuleManagerArguments.class);
+    @Nullable private Logger log;
 
     /** Brief info about installed modules. */
     @Parameter(names= {"-l", "--list"})
@@ -75,6 +74,14 @@ public class ModuleManagerArguments extends AbstractIdPHomeAwareCommandLineArgum
     @Parameter(names= {"-s", "--http-security"})
     @Nullable @NotEmpty private String httpClientSecurityParametersName;
 
+    /** {@inheritDoc} */
+    public Logger getLog() {
+        if (log == null) {
+            log = LoggerFactory.getLogger(ModuleManagerArguments.class);
+        }
+        return log;
+    }
+
     /**
      * Are we doing a list?
      * 
@@ -148,7 +155,7 @@ public class ModuleManagerArguments extends AbstractIdPHomeAwareCommandLineArgum
                 list = true;
             }
         } else if (list || fullList) {
-            log.error("Cannot list and enable/disable in the same operation");
+            getLog().error("Cannot list and enable/disable in the same operation");
             throw new IllegalArgumentException("Cannot list and enable/disable in the same operation.");
         }
     }
@@ -180,5 +187,4 @@ public class ModuleManagerArguments extends AbstractIdPHomeAwareCommandLineArgum
                 "Use the named bean for HTTP security"));
         out.println();
     }
-
 }
\ No newline at end of file
diff --git a/idp-core/src/main/java/net/shibboleth/idp/cli/DataSealerArguments.java b/idp-core/src/main/java/net/shibboleth/idp/cli/DataSealerArguments.java
index 90f359ebf..30fc09a40 100644
--- a/idp-core/src/main/java/net/shibboleth/idp/cli/DataSealerArguments.java
+++ b/idp-core/src/main/java/net/shibboleth/idp/cli/DataSealerArguments.java
@@ -21,6 +21,9 @@ import java.io.PrintStream;
 
 import javax.annotation.Nullable;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.beust.jcommander.Parameter;
 
 import net.shibboleth.utilities.java.support.security.DataSealer;
@@ -36,6 +39,9 @@ public class DataSealerArguments extends net.shibboleth.ext.spring.cli.AbstractC
     @Parameter(names = "--dataSealer")
     @Nullable private String dataSealerName;
 
+    /** The Log. */
+    @Nullable private Logger log;
+
     /** Operation enum. */
     public enum OperationType {
         /** Wrap/encrypt. */
@@ -46,7 +52,15 @@ public class DataSealerArguments extends net.shibboleth.ext.spring.cli.AbstractC
     
     /** Requested operation. */
     @Nullable private OperationType operation;
-    
+
+    /** {@inheritDoc} */
+    public Logger getLog() {
+        if (log == null) {
+            log = LoggerFactory.getLogger(DataSealerArguments.class);
+        }
+        return log;
+    }
+
     /**
      * Get name of {@link DataSealer} bean to access.
      * 
@@ -97,5 +111,4 @@ public class DataSealerArguments extends net.shibboleth.ext.spring.cli.AbstractC
         out.println(String.format("  --%-20s %s", "dataSealer", "Specifies a non-default DataSealer bean to use."));
         out.println();
     }
-
 }
\ No newline at end of file
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java
index 1bcdb7927..7d65509ef 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java
@@ -24,6 +24,7 @@ import java.net.URL;
 import java.nio.file.Path;
 import java.util.List;
 
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.apache.http.client.HttpClient;
@@ -41,7 +42,7 @@ import net.shibboleth.idp.plugin.PluginVersion;
 public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArguments {
 
     /** Logger. */
-    private final Logger log = LoggerFactory.getLogger(PluginInstallerArguments.class);
+    @Nullable private Logger log;
 
     /** The PluginId - usually used to drive the update. */
     @Parameter(names= {"-p", "--pluginId"})
@@ -98,7 +99,15 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
     };
 
     /** What to do. */
-    private OperationType operation = OperationType.UNKNOWN;
+    @Nonnull private OperationType operation = OperationType.UNKNOWN;
+
+    /** {@inheritDoc} */
+    public Logger getLog() {
+        if (log == null) {
+            log = LoggerFactory.getLogger(PluginInstallerArguments.class);
+        }
+        return log;
+    }
 
     /** Plugin Id (if specified).
      * @return {@link #pluginId}
@@ -177,6 +186,7 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
     /** {@inheritDoc} */
     // Checkstyle: CyclomaticComplexity OFF
     public void validate() throws IllegalArgumentException {
+        System.out.println("Validate");
         super.validate();
 
         final List<String> otherArgs = getOtherArgs();
@@ -190,22 +200,22 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
                     output.append(' ');
                 }
             }
-            log.error("Unexpected extra arguments {}", output);
+            getLog().error("Unexpected extra arguments {}", output);
             throw new IllegalArgumentException("Unexpected extra arguments");
         }
         if (list || fullList) {
             operation = OperationType.LIST;
             if (input !=  null) {
-                log.error("Cannot List and Install in the same operation.");
+                getLog().error("Cannot List and Install in the same operation.");
                 throw new IllegalArgumentException("Cannot List and Install in the same operation.");
             }
             if (updatePluginId !=  null) {
-                log.error("Cannot List and Update in the same operation.");
+                getLog().error("Cannot List and Update in the same operation.");
                 throw new IllegalArgumentException("Cannot List and Update in the same operation.");
             }
         } else if (input != null) {
             if (updatePluginId !=  null) {
-                log.error("Cannot Install and Update in the same operation.");
+                getLog().error("Cannot Install and Update in the same operation.");
                 throw new IllegalArgumentException("Cannot List and Update in the same operation.");
             }
             operation = decodeInput() ;
@@ -216,7 +226,7 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
                 updateVersion = new PluginVersion(forceUpdateVersion);
             }
         } else {
-            log.error("Missing qualifier. Options are : -l, -fl, -i, -u");
+            getLog().error("Missing qualifier. Options are : -l, -fl, -i, -u");
             throw new IllegalArgumentException("Missing qualifier");
         }
     }
@@ -232,22 +242,22 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
                 final int i = input.lastIndexOf('/')+1;
                 inputURL = new URL(input.substring(0, i));
                 inputName = input.substring(i);
-                log.trace("Found URL: {}\t{}", inputDirectory, inputName);
+                getLog().trace("Found URL: {}\t{}", inputDirectory, inputName);
                 return OperationType.INSTALLREMOTE;
             }
         } catch (final MalformedURLException e) {
-            log.trace("urg");
+            getLog().trace("urg");
         }
         // Must be a file
         final File inputAsFile = new File(input);
         if (!inputAsFile.exists()) {
-            log.error("File {} does not exist", inputAsFile.getAbsolutePath());
+            getLog().error("File {} does not exist", inputAsFile.getAbsolutePath());
             throw new IllegalArgumentException("Input File does not exist");
         }
         final Path inputAsPath = Path.of(inputAsFile.getAbsolutePath());
         inputDirectory = inputAsPath.getParent();
         inputName = inputAsPath.getFileName().toString();
-        log.trace("Found File: {}\t{}", inputDirectory, inputName);
+        getLog().trace("Found File: {}\t{}", inputDirectory, inputName);
         return OperationType.INSTALLDIR;
     }
 
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
index 256bb2c74..f7315f68c 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
@@ -60,10 +60,10 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
     @Nullable private Logger log;
     
     /** A Plugin Installer to use. */
-    private PluginInstaller installer;
+    @Nullable private PluginInstaller installer;
     
     /** The injected HttpClient. */
-    private HttpClient httpClient;
+    @Nullable private HttpClient httpClient;
 
     /**
      * Constrained Constructor.

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list