tvand commented on code in PR #120:
URL: https://github.com/apache/commons-jcs/pull/120#discussion_r1038864197


##########
commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/LogManager.java:
##########
@@ -57,15 +61,34 @@ private static LogFactory createLogFactory()
                 LogManager.logSystem = System.getProperty("jcs.logSystem",
                         LOGSYSTEM_JAVA_UTIL_LOGGING);
             }
-
-            for (final LogFactory factory : factories)
-            {
-                if (logSystem.equalsIgnoreCase(factory.getName()))
-                {
-                    return factory;
+            List<ServiceConfigurationError> errors = new ArrayList<>();
+            Iterator<LogFactory> itr = factories.iterator();
+            LogFactory factory = null;
+            while (itr.hasNext()) {
+                try {
+                    LogFactory instance = itr.next();
+                    if (logSystem.equalsIgnoreCase(instance.getName())) {
+                        factory = instance;
+                        break;
+                    }
+                } catch (ServiceConfigurationError e) {
+                    errors.add(e);
                 }
             }
-
+            if (factory != null) {
+                if (!errors.isEmpty()) {
+                    Log log = factory.getLog(LogFactoryHolder.class);
+                    for (ServiceConfigurationError error : errors) {
+                        log.debug("Error loading LogFactory", error);
+                    }
+                    log.debug("Found LogFacgtory for " + logSystem);

Review Comment:
   typo?



##########
commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/LogManager.java:
##########
@@ -57,15 +61,34 @@ private static LogFactory createLogFactory()
                 LogManager.logSystem = System.getProperty("jcs.logSystem",
                         LOGSYSTEM_JAVA_UTIL_LOGGING);
             }
-
-            for (final LogFactory factory : factories)
-            {
-                if (logSystem.equalsIgnoreCase(factory.getName()))
-                {
-                    return factory;
+            List<ServiceConfigurationError> errors = new ArrayList<>();
+            Iterator<LogFactory> itr = factories.iterator();
+            LogFactory factory = null;
+            while (itr.hasNext()) {
+                try {
+                    LogFactory instance = itr.next();
+                    if (logSystem.equalsIgnoreCase(instance.getName())) {
+                        factory = instance;
+                        break;
+                    }
+                } catch (ServiceConfigurationError e) {
+                    errors.add(e);
                 }
             }
-
+            if (factory != null) {
+                if (!errors.isEmpty()) {
+                    Log log = factory.getLog(LogFactoryHolder.class);
+                    for (ServiceConfigurationError error : errors) {
+                        log.debug("Error loading LogFactory", error);
+                    }
+                    log.debug("Found LogFacgtory for " + logSystem);
+                }
+                return factory;
+            }
+            if (!errors.isEmpty()) {
+                throw new RuntimeException("Could not find factory 
implementation for log subsystem " + logSystem,
+                        errors.get(0));

Review Comment:
   If the list is not empty and we are getting up to here, I'd suggest to print 
out all the errors in the list first and the throw the exception.



##########
commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/LogManager.java:
##########
@@ -57,15 +61,34 @@ private static LogFactory createLogFactory()
                 LogManager.logSystem = System.getProperty("jcs.logSystem",
                         LOGSYSTEM_JAVA_UTIL_LOGGING);
             }
-
-            for (final LogFactory factory : factories)
-            {
-                if (logSystem.equalsIgnoreCase(factory.getName()))
-                {
-                    return factory;
+            List<ServiceConfigurationError> errors = new ArrayList<>();
+            Iterator<LogFactory> itr = factories.iterator();
+            LogFactory factory = null;
+            while (itr.hasNext()) {
+                try {
+                    LogFactory instance = itr.next();
+                    if (logSystem.equalsIgnoreCase(instance.getName())) {
+                        factory = instance;
+                        break;
+                    }
+                } catch (ServiceConfigurationError e) {
+                    errors.add(e);
                 }
             }
-
+            if (factory != null) {
+                if (!errors.isEmpty()) {
+                    Log log = factory.getLog(LogFactoryHolder.class);

Review Comment:
   What is LogFactoryHolder? What kind of log system do you use here? I think I 
understand your intention but we have like a chicken-and-egg problem here. I'd 
rather not instantiate a logger while trying to select a log system. WDYT?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to