Commits

David Carr  committed 83d1e17

Add support for overriding the logging configuration

  • Participants
  • Parent commits 5204324

Comments (0)

Files changed (2)

File app/src/main/java/deepdiff/app/DeepDiff.java

 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+import org.apache.log4j.xml.DOMConfigurator;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
      * @param args the command-line arguments
      */
     public static void main(String[] args) {
+        configureLogging();
         DeepDiff app = new DeepDiff();
         try {
             CommandLine cl = app.parseCommandLine(args);
         }
     }
 
+    private static void configureLogging() {
+        System.setProperty("log4j.defaultInitOverride", "true");
+        File configXml = new File("log4j.xml");
+        File configProps = new File("log4j.properties");
+        if(configXml.exists()) {
+            DOMConfigurator.configure(configXml.getPath());
+        } else if(configProps.exists()) {
+            PropertyConfigurator.configure(configProps.getPath());
+        } else {
+            PropertyConfigurator.configure(DeepDiff.class.getResource("/log4j.properties"));
+        }
+    }
+
     /**
      * Parses a command-line
      * 

File engine/src/test/java/deepdiff/test/TestLogAppender.java

-/*
- * Copyright 2011 DeepDiff Contributors
- *
- * Licensed 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 deepdiff.test;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.Logger;
-import org.apache.log4j.spi.LoggingEvent;
-
-public class TestLogAppender extends AppenderSkeleton {
-    private List<LoggingEvent> events = new LinkedList<LoggingEvent>();
-
-    @Override
-    public void close() {
-    }
-
-    @Override
-    public boolean requiresLayout() {
-        return false;
-    }
-
-    @Override
-    protected void append(LoggingEvent event) {
-        events.add(event);
-    }
-
-    public List<LoggingEvent> getEvents() {
-        return events;
-    }
-
-    public void install() {
-        Logger.getRootLogger().addAppender(this);
-    }
-
-    public void uninstall() {
-        Logger.getRootLogger().removeAppender(this);
-    }
-}
+/*
+ * Copyright 2011 DeepDiff Contributors
+ *
+ * Licensed 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 deepdiff.test;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.LoggingEvent;
+
+import org.junit.Ignore;
+
+@Ignore
+public class TestLogAppender extends AppenderSkeleton {
+    private List<LoggingEvent> events = new LinkedList<LoggingEvent>();
+
+    @Override
+    public void close() {
+    }
+
+    @Override
+    public boolean requiresLayout() {
+        return false;
+    }
+
+    @Override
+    protected void append(LoggingEvent event) {
+        events.add(event);
+    }
+
+    public List<LoggingEvent> getEvents() {
+        return events;
+    }
+
+    public void install() {
+        Logger.getRootLogger().addAppender(this);
+    }
+
+    public void uninstall() {
+        Logger.getRootLogger().removeAppender(this);
+    }
+}