You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by re...@apache.org on 2014/07/23 20:24:28 UTC
svn commit: r1612908 - in
/incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap:
DeviceMapClient.java Util.java cmd/Main.java loader/impl/DDRLoader.java
Author: rezan
Date: Wed Jul 23 18:24:28 2014
New Revision: 1612908
URL: http://svn.apache.org/r1612908
Log:
java logging
Modified:
incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/DeviceMapClient.java
incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/Util.java
incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/cmd/Main.java
incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/loader/impl/DDRLoader.java
Modified: incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/DeviceMapClient.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/DeviceMapClient.java?rev=1612908&r1=1612907&r2=1612908&view=diff
==============================================================================
--- incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/DeviceMapClient.java (original)
+++ incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/DeviceMapClient.java Wed Jul 23 18:24:28 2014
@@ -24,6 +24,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.devicemap.data.Device;
import org.apache.devicemap.loader.LoaderOption;
@@ -32,7 +34,8 @@ import org.apache.devicemap.loader.Loade
public class DeviceMapClient {
- private static boolean printWarnings = true;
+ private final static Logger LOG = Logger.getLogger(DeviceMapClient.class.getName());
+
private static long initCount = 0;
//indexes
@@ -59,8 +62,8 @@ public class DeviceMapClient {
initCount++;
- if (printWarnings && initCount % 1000 == 0) {
- Util.errorLog("Possible device data over-initialization detected");
+ if (initCount % 1000 == 0) {
+ LOG.log(Level.WARNING, "Possible device data over-initialization detected");
}
if (devices == null) {
@@ -107,7 +110,7 @@ public class DeviceMapClient {
return null;
}
- Util.debugLog("classify: '" + text + "'");
+ LOG.log(Level.FINE, "classify: '" + text + "'");
String[] parts = text.split(" |-|_|/|\\\\|\\[|\\]|\\(|\\)|;");
@@ -127,7 +130,7 @@ public class DeviceMapClient {
hits.put(pattern, dlist);
for (DeviceType device : dlist) {
- Util.debugLog("Hit found: '" + pattern + "' => id: '" + device.getId() + "' " + device.getPatterns());
+ LOG.log(Level.FINER, "Hit found: '" + pattern + "' => id: '" + device.getId() + "' " + device.getPatterns());
}
}
}
@@ -140,7 +143,7 @@ public class DeviceMapClient {
continue;
}
- Util.debugLog("Hit candidate: " + hit + " => " + device.getId());
+ LOG.log(Level.FINER, "Hit candidate: " + hit + " => " + device.getId());
if (winner != null) {
if ("simple".equals(winner.getType()) && !"simple".equals(device.getType())) {
@@ -159,7 +162,7 @@ public class DeviceMapClient {
}
if (winner != null) {
- Util.debugLog("Result: " + winner);
+ LOG.log(Level.FINE, "Result: " + winner);
return winner.getAttributes();
} else {
return null;
@@ -198,8 +201,4 @@ public class DeviceMapClient {
}
return count;
}
-
- public static void setPrintWarnings(boolean aPrintWarnings) {
- printWarnings = aPrintWarnings;
- }
}
Modified: incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/Util.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/Util.java?rev=1612908&r1=1612907&r2=1612908&view=diff
==============================================================================
--- incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/Util.java (original)
+++ incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/Util.java Wed Jul 23 18:24:28 2014
@@ -43,15 +43,4 @@ public class Util {
return ret.toString();
}
-
- public static void errorLog(String msg) {
- System.err.println("[devicemapjava] ERROR: " + msg);
- }
-
- public static void debugLog(String msg) {
- if (System.getProperty("debug") == null) {
- return;
- }
- System.out.println("[devicemapjava] " + msg);
- }
}
Modified: incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/cmd/Main.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/cmd/Main.java?rev=1612908&r1=1612907&r2=1612908&view=diff
==============================================================================
--- incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/cmd/Main.java (original)
+++ incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/cmd/Main.java Wed Jul 23 18:24:28 2014
@@ -21,11 +21,16 @@ package org.apache.devicemap.cmd;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.devicemap.Constants;
import org.apache.devicemap.DeviceMapClient;
import org.apache.devicemap.data.Device;
import org.apache.devicemap.loader.LoaderOption;
+import org.apache.devicemap.loader.impl.DDRLoader;
public class Main {
@@ -74,7 +79,13 @@ public class Main {
}
if(debug) {
- System.setProperty("debug", "true");
+ Logger.getLogger(DeviceMapClient.class.getName()).setLevel(Level.ALL);
+ Logger.getLogger(DDRLoader.class.getName()).setLevel(Level.ALL);
+ for (Handler h : Logger.getLogger(DeviceMapClient.class.getName()).getParent().getHandlers()) {
+ if (h instanceof ConsoleHandler) {
+ h.setLevel(Level.ALL);
+ }
+ }
}
if ("default".equals(loaderPath)) {
Modified: incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/loader/impl/DDRLoader.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/loader/impl/DDRLoader.java?rev=1612908&r1=1612907&r2=1612908&view=diff
==============================================================================
--- incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/loader/impl/DDRLoader.java (original)
+++ incubator/devicemap/trunk/devicemap/java/classifier/src/main/java/org/apache/devicemap/loader/impl/DDRLoader.java Wed Jul 23 18:24:28 2014
@@ -27,6 +27,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.devicemap.Constants;
import org.apache.devicemap.data.DeviceType;
@@ -36,6 +38,8 @@ import org.apache.devicemap.loader.Resou
import org.apache.devicemap.loader.parser.XMLParser;
public class DDRLoader implements Loader {
+
+ private final static Logger LOG = Logger.getLogger(DDRLoader.class.getName());
private final Map<String, DeviceType> devices;
@@ -55,7 +59,7 @@ public class DDRLoader implements Loader
ddin.close();
long diff = System.currentTimeMillis() - start;
- Util.debugLog("Loaded " + Constants.DEVICE_DATA + " in " + diff + "ms");
+ LOG.log(Level.FINE, "Loaded " + Constants.DEVICE_DATA + " in " + diff + "ms");
try {
start = System.currentTimeMillis();
@@ -65,9 +69,9 @@ public class DDRLoader implements Loader
ddpin.close();
diff = System.currentTimeMillis() - start;
- Util.debugLog("Loaded " + Constants.DEVICE_DATA_PATCH + " in " + diff + "ms");
+ LOG.log(Level.FINE, "Loaded " + Constants.DEVICE_DATA_PATCH + " in " + diff + "ms");
} catch (FileNotFoundException ex) {
- Util.debugLog("WARNING: file not found " + Constants.DEVICE_DATA_PATCH + ": " + ex.toString());
+ LOG.log(Level.WARNING, "File not found " + Constants.DEVICE_DATA_PATCH + ": " + ex.toString());
}
setParentAttributes();
@@ -79,7 +83,7 @@ public class DDRLoader implements Loader
bin.close();
diff = System.currentTimeMillis() - start;
- Util.debugLog("Loaded " + Constants.BUILDER_DATA + " in " + diff + "ms");
+ LOG.log(Level.FINE, "Loaded " + Constants.BUILDER_DATA + " in " + diff + "ms");
try {
start = System.currentTimeMillis();
@@ -89,9 +93,9 @@ public class DDRLoader implements Loader
bpin.close();
diff = System.currentTimeMillis() - start;
- Util.debugLog("Loaded " + Constants.BUILDER_DATA_PATCH + " in " + diff + "ms");
+ LOG.log(Level.FINE, "Loaded " + Constants.BUILDER_DATA_PATCH + " in " + diff + "ms");
} catch (FileNotFoundException ex) {
- Util.debugLog("WARNING: file not found " + Constants.BUILDER_DATA_PATCH + ": " + ex.toString());
+ LOG.log(Level.WARNING, "File not found " + Constants.BUILDER_DATA_PATCH + ": " + ex.toString());
}
return getDevices();
@@ -184,7 +188,7 @@ public class DDRLoader implements Loader
device.setType("weak");
}
} else {
- Util.debugLog("ERROR: device not found: '" + id + "'");
+ LOG.log(Level.FINE, "ERROR: device not found: '" + id + "'");
}
//reset the device