svn commit: r1782072 - in /ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt: BirtWorker.java container/BirtContainer.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1782072 - in /ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt: BirtWorker.java container/BirtContainer.java

nmalin
Author: nmalin
Date: Tue Feb  7 19:57:13 2017
New Revision: 1782072

URL: http://svn.apache.org/viewvc?rev=1782072&view=rev
Log:
Fixed: Birt logging unlogical high (OFBIZ-9201)
Backport from trunk. Currently the class BirtContainer call the birt engine with hard coded log level ALL that generated huge log file.
We can't implement easily log4j on the birt engine so with this commit I create a quick fix to have matching between the java.util.Logger and org.apache.log4j.Logger level.
You can select the log level from debug.properties to populate the ReportEngine log file.

Modified:
    ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt/BirtWorker.java
    ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt/container/BirtContainer.java

Modified: ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt/BirtWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt/BirtWorker.java?rev=1782072&r1=1782071&r2=1782072&view=diff
==============================================================================
--- ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt/BirtWorker.java (original)
+++ ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt/BirtWorker.java Tue Feb  7 19:57:13 2017
@@ -20,8 +20,10 @@ package org.ofbiz.birt;
 
 import java.io.OutputStream;
 import java.sql.SQLException;
+import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
+import java.util.logging.Level;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -29,6 +31,7 @@ import javax.servlet.http.HttpServletRes
 import javax.servlet.http.HttpSession;
 
 import org.eclipse.birt.report.engine.api.EXCELRenderOption;
+import org.eclipse.birt.report.engine.api.EngineConfig;
 import org.eclipse.birt.report.engine.api.EngineException;
 import org.eclipse.birt.report.engine.api.HTMLRenderOption;
 import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
@@ -41,6 +44,7 @@ import org.eclipse.birt.report.engine.ap
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilGenerics;
+import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.security.Security;
@@ -59,6 +63,18 @@ public class BirtWorker {
 
     private static HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();
 
+    public static final Map<Integer, Level> levelIntMap = new HashMap<>();
+    static {
+        levelIntMap.put(Debug.ERROR, Level.SEVERE);
+        levelIntMap.put(Debug.TIMING, Level.FINE);
+        levelIntMap.put(Debug.INFO, Level.INFO);
+        levelIntMap.put(Debug.IMPORTANT, Level.INFO);
+        levelIntMap.put(Debug.WARNING, Level.WARNING);
+        levelIntMap.put(Debug.ERROR, Level.SEVERE);
+        levelIntMap.put(Debug.FATAL, Level.ALL);
+        levelIntMap.put(Debug.ALWAYS, Level.ALL);
+    }
+
     /**
      * export report
      * @param design
@@ -193,4 +209,21 @@ public class BirtWorker {
             appContext.put("security", security);
         }
     }
+
+    /**
+     * initialize configuration log with the low level present on debug.properties
+     * @param config
+     */
+    public static void setLogConfig(EngineConfig config) {
+        String ofbizHome = System.getProperty("ofbiz.home");
+        int lowerLevel = 0;
+        //resolve the lower level open on debug.properties, maybe it's better to implement correctly log4j here
+        for (int i = 1; i < 7; i++) {
+            if (Debug.isOn(i)) {
+                lowerLevel = i;
+                break;
+            }
+        }
+        config.setLogConfig(UtilProperties.getPropertyValue("debug", "log4j.appender.css.dir", ofbizHome + "/runtime/logs/"), levelIntMap.get(lowerLevel));
+    }
 }

Modified: ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt/container/BirtContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt/container/BirtContainer.java?rev=1782072&r1=1782071&r2=1782072&view=diff
==============================================================================
--- ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt/container/BirtContainer.java (original)
+++ ofbiz/branches/release15.12/specialpurpose/birt/src/org/ofbiz/birt/container/BirtContainer.java Tue Feb  7 19:57:13 2017
@@ -19,8 +19,6 @@
 package org.ofbiz.birt.container;
 
 import java.io.File;
-import java.util.logging.Level;
-
 import org.eclipse.birt.core.exception.BirtException;
 import org.eclipse.birt.core.framework.Platform;
 import org.eclipse.birt.report.IBirtConstants;
@@ -32,11 +30,12 @@ import org.ofbiz.base.container.Containe
 import org.ofbiz.base.container.ContainerException;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.birt.BirtFactory;
+import org.ofbiz.birt.BirtWorker;
 
 public class BirtContainer implements Container {
 
     public static final String module = BirtContainer.class.getName();
-    
+
     protected String configFile;
 
     private String name;
@@ -68,11 +67,13 @@ public class BirtContainer implements Co
         EngineConfig config = new EngineConfig();
         String ofbizHome = System.getProperty("ofbiz.home");
         config.setTempDir(ofbizHome + File.separatorChar + "runtime" + File.separatorChar + "tempfiles");
-        config.setLogConfig(ofbizHome + File.separatorChar + "runtime" + File.separatorChar + "logs" + File.separatorChar + "birt", Level.ALL);
 
         // set system properties
         System.setProperty(IBirtConstants.SYS_PROP_WORKING_PATH, config.getTempDir());
 
+        //Set log config
+        BirtWorker.setLogConfig(config);
+
         // startup platform
         try {
             Debug.logInfo("Startup BIRT platform", module);