Author: nmalin
Date: Fri Aug  5 12:05:48 2016
New Revision: 1755302

URL: http://svn.apache.org/viewvc?rev=1755302&view=rev
Log:
Currently we have two methods for display log in OFBiz throught webtools :
* https://localhost:8443/webtools/control/LogView
* https://localhost:8443/webtools/control/FetchLogs
Each method use the same line rendering and the difference is : LogView display 
only runtime/logs/ofbiz.log (or you can surcharge it vith debug.properties) and 
FecthLogs list all file name ofbiz* present on runtime/logs/ofbiz.log and 
offert the possibility to search only line that macth a string.

I review the code to use only one script (remove LogView.groovy) and improve 
following points :
* Optimise the FetchLog.groovy to display with same velocity a file with or 
without string chain filtering
* Add a property to change the root log directory. Under linux we use 
/var/log/ofbiz/
* Add a regExp to match the file name of file present in the directory. Helpful 
when you want to see error.log
* Complete debug.properties with comment for describe example for new properties

And last point, add refresh button on the end page to reload the log without 
lost your state on the page.
Related issue OFBIZ-7944

Removed:
    ofbiz/trunk/framework/webtools/groovyScripts/log/LogView.groovy
Modified:
    ofbiz/trunk/framework/base/config/debug.properties
    ofbiz/trunk/framework/webtools/groovyScripts/log/FetchLogs.groovy
    ofbiz/trunk/framework/webtools/widget/LogScreens.xml

Modified: ofbiz/trunk/framework/base/config/debug.properties
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/config/debug.properties?rev=1755302&r1=1755301&r2=1755302&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/config/debug.properties (original)
+++ ofbiz/trunk/framework/base/config/debug.properties Fri Aug  5 12:05:48 2016
@@ -29,3 +29,10 @@ print.important=true
 print.warning=true
 print.error=true
 print.fatal=true
+
+## Root log location to display on webtools 
https://localhost:8443/webtools/control/LogView
+# log4j.appender.css.dir=runtime/logs/
+## File to display on webtools https://localhost:8443/webtools/control/LogView
+# log4j.appender.css.defaultFile=ofbiz.log
+## RegExp use to filter file available on dropdown selection to diplay log on 
https://localhost:8443/webtools/control/FetchLog
+# log4j.appender.css.fileNameRegExp=[(ofbiz)|(error)].*
\ No newline at end of file

Modified: ofbiz/trunk/framework/webtools/groovyScripts/log/FetchLogs.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/groovyScripts/log/FetchLogs.groovy?rev=1755302&r1=1755301&r2=1755302&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/groovyScripts/log/FetchLogs.groovy (original)
+++ ofbiz/trunk/framework/webtools/groovyScripts/log/FetchLogs.groovy Fri Aug  
5 12:05:48 2016
@@ -18,16 +18,24 @@
 */
 
 import org.apache.ofbiz.base.util.FileUtil;
+import org.apache.ofbiz.base.util.UtilProperties;
 
-ofbizHomeStr = System.getProperty("ofbiz.home");
-ofbizHomeStr = ofbizHomeStr + "/runtime/logs/";
-File runTimeLogDir = FileUtil.getFile(ofbizHomeStr);
-File[] listLogFiles = runTimeLogDir.listFiles(); 
+String ofbizLogDir = UtilProperties.getPropertyValue("debug", 
"log4j.appender.css.dir", "runtime/logs/");
+if (!ofbizLogDir.startsWith("/")) {
+    ofbizLogDir = System.getProperty("ofbiz.home") + "/" + ofbizLogDir;
+}
+if (!ofbizLogDir.endsWith("/")) {
+    ofbizLogDir.concat("/");
+}
+
+File runTimeLogDir = FileUtil.getFile(ofbizLogDir);
+File[] listLogFiles = runTimeLogDir.listFiles();
+String ofbizLogRegExp = UtilProperties.getPropertyValue("debug", 
"log4j.appender.css.fileNameRegExp", "[(ofbiz)|(error)].*");
 List listLogFileNames = []
 for (int i = 0; i < listLogFiles.length; i++) {
     if (listLogFiles[i].isFile()) {
         logFileName = listLogFiles[i].getName();
-        if (logFileName.startsWith("ofbiz")) {
+        if (logFileName.matches(ofbizLogRegExp)) {
             listLogFileNames.add(logFileName);
         }
     }
@@ -35,27 +43,27 @@ for (int i = 0; i < listLogFiles.length;
 context.listLogFileNames = listLogFileNames;
 
 if (parameters.logFileName) {
-    logFileName = ofbizHomeStr + parameters.logFileName;
     List logLines = [];
-    File logFile = FileUtil.getFile(logFileName);
-    logFile.eachLine { line ->
-        type = '';
-        if (line.contains(":INFO ] ")) {
-            type = 'INFO';
-        } else if (line.contains(":WARN ] ")) {
-            type = 'WARN';
-        } else if (line.contains(":ERROR] ")) {
-            type = 'ERROR';
-        } else if (line.contains(":DEBUG] ")) {
-            type = 'DEBUG';
-        }
-        if (parameters.searchString) {
-            if (line.contains(parameters.searchString)) {
-                logLines.add([type: type, line:line]);
+    try {
+        File logFile = 
FileUtil.getFile(ofbizLogDir.concat(parameters.logFileName));
+        logFile.eachLine { line ->
+            if (parameters.searchString) {
+                if (!line.contains(parameters.searchString)) {
+                    return;
+                }
+            }
+            type = '';
+            if (line.contains(" |I| ")) {
+                type = 'INFO';
+            } else if (line.contains(" |W| ")) {
+                type = 'WARN';
+            } else if (line.contains(" |E| ")) {
+                type = 'ERROR';
+            } else if (line.contains(" |D| ")) {
+                type = 'DEBUG';
             }
-        } else {
             logLines.add([type: type, line:line]);
         }
-    }
+    } catch (Exception exc) {}
     context.logLines = logLines;
-}
\ No newline at end of file
+}

Modified: ofbiz/trunk/framework/webtools/widget/LogScreens.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/widget/LogScreens.xml?rev=1755302&r1=1755301&r2=1755302&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/widget/LogScreens.xml (original)
+++ ofbiz/trunk/framework/webtools/widget/LogScreens.xml Fri Aug  5 12:05:48 
2016
@@ -98,10 +98,8 @@ under the License.
              <actions>
                  <set field="titleProperty" value="PageTitleLogView"/>
                  <set field="tabButtonItem" value="logView"/>
-                 <!-- TODO: the following command is not really working (and 
the default value is always used);
-                              my guess is that the 
base/config/debug.properties file is not found in the classpath -->
-                 <property-to-field resource="debug" 
property="log4j.appender.css.File" field="logFileName" 
default="runtime/logs/ofbiz.log" no-locale="true"/>
-                 <script 
location="component://webtools/groovyScripts/log/LogView.groovy"/>
+                 <property-to-field field="parameters.logFileName" 
resource="debug" property="log4j.appender.css.defaultFile" default="ofbiz.log" 
no-locale="true"/>
+                 <script 
location="component://webtools/groovyScripts/log/FetchLogs.groovy"/>
              </actions>
              <widgets>
                  <decorator-screen name="log-decorator">
@@ -117,6 +115,9 @@ under the License.
                              <platform-specific>
                                  <html><html-template 
location="component://webtools/template/log/LogContent.ftl"/></html>
                              </platform-specific>
+                             <container style="button-bar">
+                                 <link target="javascript: 
window.location.reload();" text="${uiLabelMap.CommonRefresh}" style="buttontext 
refresh" url-mode="plain"/>
+                             </container>
                          </screenlet>
                      </decorator-section>
                  </decorator-screen>
@@ -138,6 +139,9 @@ under the License.
                              <platform-specific>
                                  <html><html-template 
location="component://webtools/template/log/FetchLogs.ftl"/></html>
                              </platform-specific>
+                             <container style="button-bar">
+                                 <link target="javascript: 
window.location.reload();" text="${uiLabelMap.CommonRefresh}" style="buttontext 
refresh" url-mode="plain"/>
+                             </container>
                          </screenlet>
                      </decorator-section>
                  </decorator-screen>


Reply via email to