Small updates

This commit is contained in:
Ziver Koc 2016-05-25 14:27:44 +02:00
parent c894ba8a61
commit 31ab57dec1
3 changed files with 23 additions and 8 deletions

View file

@ -153,10 +153,13 @@ public class CompactLogFormatter extends Formatter{
*/ */
private String paddClassName(String source){ private String paddClassName(String source){
String cStr = padd_cache.get(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 cStr = source.substring(source.lastIndexOf('.') + 1); // Remove packages
if(cStr.lastIndexOf('$') >= 0) // extract subclass name if (cStr.lastIndexOf('$') >= 0) { // extract subclass name
cStr = cStr.substring(cStr.lastIndexOf('$')+1); 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) if (cStr.length() > max_class_name)
max_class_name = cStr.length(); max_class_name = cStr.length();

View file

@ -26,9 +26,12 @@ package zutil.log;
import zutil.io.file.FileUtil; import zutil.io.file.FileUtil;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.util.logging.*; import java.util.logging.*;
import static java.lang.System.in;
/** /**
* Utility functions for the standard Java Logger * Utility functions for the standard Java Logger
* *
@ -130,11 +133,16 @@ public class LogUtil {
public static void readConfiguration(String file){ public static void readConfiguration(String file){
try{ try{
FileInputStream in = new FileInputStream(FileUtil.find(file)); File confFile = FileUtil.find(file);
if (confFile != null) {
FileInputStream in = new FileInputStream(confFile);
LogManager.getLogManager().readConfiguration(in); LogManager.getLogManager().readConfiguration(in);
in.close(); in.close();
}
else
logger.warning("Unable to find logging configuration file: "+file);
} catch (Exception e){ } catch (Exception e){
logger.log(Level.SEVERE, null, e); logger.log(Level.SEVERE, "Unable to load logging configuration: "+file, e);
} }
} }
} }

View file

@ -33,6 +33,7 @@ public class NutUPSClient {
private static final String PARAMETER_POWER_LOAD = "ups.load"; //ups.power 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_POWER_USAGE = "ups.realpower"; //ups.power
private static final String PARAMETER_BATTERY_CHARGE = "battery.charge"; 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"; private static final String PARAMETER_POLL_INTERVAL = "driver.parameter.pollinterval";
@ -66,7 +67,7 @@ public class NutUPSClient {
protected synchronized void update(){ protected synchronized void update(){
if(pollTimer.hasTimedOut()){ if(pollTimer.hasTimedOut()){
logger.fine("Starting UPS data refresh"); logger.fine("Starting UPS data refresh ("+host+":"+port+")");
try(Socket s = new Socket(host, port)) { try(Socket s = new Socket(host, port)) {
Writer out = new OutputStreamWriter(s.getOutputStream()); Writer out = new OutputStreamWriter(s.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
@ -162,6 +163,9 @@ public class NutUPSClient {
public int getBatteryCharge(){ public int getBatteryCharge(){
return Integer.parseInt(parameters.get(PARAMETER_BATTERY_CHARGE)); return Integer.parseInt(parameters.get(PARAMETER_BATTERY_CHARGE));
} }
public double getBatteryVoltage(){
return Double.parseDouble(parameters.get(PARAMETER_BATTERY_VOLTAGE));
}
} }
} }