Revision: 16727
          http://sourceforge.net/p/gate/code/16727
Author:   ian_roberts
Date:     2013-07-08 11:12:19 +0000 (Mon, 08 Jul 2013)
Log Message:
-----------
Added a new "NONE" log level that goes beyond the current MINIMUM level (0) and
does not even try to open a log file.  This mode should be used in applications
that will be running in a multithreaded environment, to avoid collisions over
the (static) LogService between the different instances of the Learning PR.

Also allow verbosity level to be specified in words (NONE, MINIMUM, NORMAL or
DEBUG) instead of numbers (-1, 0, 1 or 2).

Modified Paths:
--------------
    gate/trunk/plugins/Learning/src/gate/learning/LearningEngineSettings.java
    gate/trunk/plugins/Learning/src/gate/learning/LogService.java

Modified: 
gate/trunk/plugins/Learning/src/gate/learning/LearningEngineSettings.java
===================================================================
--- gate/trunk/plugins/Learning/src/gate/learning/LearningEngineSettings.java   
2013-07-08 10:28:56 UTC (rev 16726)
+++ gate/trunk/plugins/Learning/src/gate/learning/LearningEngineSettings.java   
2013-07-08 11:12:19 UTC (rev 16727)
@@ -8,6 +8,8 @@
 package gate.learning;
 
 import java.io.File;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
 import java.net.URISyntaxException;
 import java.util.Iterator;
 import java.util.concurrent.ExecutorService;
@@ -161,7 +163,21 @@
     if(rootElement.getChild("VERBOSITY") != null) {
       String value = rootElement.getChild("VERBOSITY").getAttribute("level")
         .getValue();
-      learningSettings.verbosityLogService = Integer.parseInt(value);
+      Integer logLevel = null;
+      try {
+        Field f = LogService.class.getField(value);
+        if(Modifier.isStatic(f.getModifiers()) &&
+            Modifier.isFinal(f.getModifiers()) &&
+            Integer.TYPE == f.getType()) {
+          logLevel = (Integer)f.get(null);
+        }
+      } catch(Exception e) {
+        // Do nothing, try treating it as a number instead
+      }
+      if(logLevel == null) {
+        logLevel = Integer.valueOf(value);
+      }
+      learningSettings.verbosityLogService = logLevel.intValue();
     }
     learningSettings.fiteringTrainingData = false;
     learningSettings.filteringRatio = 0.0f;

Modified: gate/trunk/plugins/Learning/src/gate/learning/LogService.java
===================================================================
--- gate/trunk/plugins/Learning/src/gate/learning/LogService.java       
2013-07-08 10:28:56 UTC (rev 16726)
+++ gate/trunk/plugins/Learning/src/gate/learning/LogService.java       
2013-07-08 11:12:19 UTC (rev 16727)
@@ -20,6 +20,8 @@
  */
 public class LogService {
   //-------------------- Verbosity Level --------------------
+  /** Absolutely no logging at all - don't even open the log file. */
+  public static final int NONE        = -1;
   /** The Minimum level, only output the error and warning information. */
   public static final int MINIMUM     = 0;
   /** The normal level, outputing the setting information and results. */
@@ -43,7 +45,10 @@
   
   /** Open the log service and set the minimum verbosity level. */
   public static void init(File logfile, boolean append, int verboLevel) throws 
IOException {
-    logFileIn = new PrintWriter(new FileWriter(logfile, append));
+    if(verboLevel > NONE) {
+      // special case - for NONE we don't even want to open the log file
+      logFileIn = new PrintWriter(new FileWriter(logfile, append));
+    }
     minVerbosityLevel = verboLevel;
   }
   
@@ -55,7 +60,7 @@
   
   /** Writes the message to the output stream if the verbosity level is high 
enough. */
   public static void logMessage(String message, int verbosityLevel) {
-    if (message == null) return;
+    if (message == null || logFileIn == null) return;
     if (verbosityLevel < minVerbosityLevel) return;
     if (message.equals(lastMessage)) {
       equalMessageCount++;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to