From 31ab57dec1ff0dec8e2ec3378c10909650a6ffee Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Wed, 25 May 2016 14:27:44 +0200 Subject: [PATCH] Small updates --- src/zutil/log/CompactLogFormatter.java | 9 ++++++--- src/zutil/log/LogUtil.java | 16 ++++++++++++---- src/zutil/osal/app/linux/NutUPSClient.java | 6 +++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/zutil/log/CompactLogFormatter.java b/src/zutil/log/CompactLogFormatter.java index c72751c..5c53571 100755 --- a/src/zutil/log/CompactLogFormatter.java +++ b/src/zutil/log/CompactLogFormatter.java @@ -153,10 +153,13 @@ public class CompactLogFormatter extends Formatter{ */ private String paddClassName(String source){ String cStr = padd_cache.get(source); - if(cStr == null || cStr.length() != max_class_name) { + if (cStr == null || cStr.length() != max_class_name) { cStr = source.substring(source.lastIndexOf('.') + 1); // Remove packages - if(cStr.lastIndexOf('$') >= 0) // extract subclass name - cStr = cStr.substring(cStr.lastIndexOf('$')+1); + if (cStr.lastIndexOf('$') >= 0) { // extract subclass name + String subClass = cStr.substring(cStr.lastIndexOf('$') + 1); + if (!Pattern.matches("\\d+", subClass)) // Don'n substring for anonymous classes + cStr = subClass; + } if (cStr.length() > max_class_name) max_class_name = cStr.length(); diff --git a/src/zutil/log/LogUtil.java b/src/zutil/log/LogUtil.java index b2aa481..5e787c5 100755 --- a/src/zutil/log/LogUtil.java +++ b/src/zutil/log/LogUtil.java @@ -26,9 +26,12 @@ package zutil.log; import zutil.io.file.FileUtil; +import java.io.File; import java.io.FileInputStream; import java.util.logging.*; +import static java.lang.System.in; + /** * Utility functions for the standard Java Logger * @@ -130,11 +133,16 @@ public class LogUtil { public static void readConfiguration(String file){ try{ - FileInputStream in = new FileInputStream(FileUtil.find(file)); - LogManager.getLogManager().readConfiguration(in); - in.close(); + File confFile = FileUtil.find(file); + if (confFile != null) { + FileInputStream in = new FileInputStream(confFile); + LogManager.getLogManager().readConfiguration(in); + in.close(); + } + else + logger.warning("Unable to find logging configuration file: "+file); } catch (Exception e){ - logger.log(Level.SEVERE, null, e); + logger.log(Level.SEVERE, "Unable to load logging configuration: "+file, e); } } } diff --git a/src/zutil/osal/app/linux/NutUPSClient.java b/src/zutil/osal/app/linux/NutUPSClient.java index ec46cc5..414d5d7 100755 --- a/src/zutil/osal/app/linux/NutUPSClient.java +++ b/src/zutil/osal/app/linux/NutUPSClient.java @@ -33,6 +33,7 @@ public class NutUPSClient { private static final String PARAMETER_POWER_LOAD = "ups.load"; //ups.power private static final String PARAMETER_POWER_USAGE = "ups.realpower"; //ups.power private static final String PARAMETER_BATTERY_CHARGE = "battery.charge"; + private static final String PARAMETER_BATTERY_VOLTAGE = "battery.voltage"; private static final String PARAMETER_POLL_INTERVAL = "driver.parameter.pollinterval"; @@ -66,7 +67,7 @@ public class NutUPSClient { protected synchronized void update(){ if(pollTimer.hasTimedOut()){ - logger.fine("Starting UPS data refresh"); + logger.fine("Starting UPS data refresh ("+host+":"+port+")"); try(Socket s = new Socket(host, port)) { Writer out = new OutputStreamWriter(s.getOutputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); @@ -162,6 +163,9 @@ public class NutUPSClient { public int getBatteryCharge(){ return Integer.parseInt(parameters.get(PARAMETER_BATTERY_CHARGE)); } + public double getBatteryVoltage(){ + return Double.parseDouble(parameters.get(PARAMETER_BATTERY_VOLTAGE)); + } } }