Use java logging instead of system out in core and plugins.

This commit is contained in:
endolf 2009-10-31 11:06:12 +00:00
parent 86fb3d5499
commit 967fde8a93
4 changed files with 25 additions and 16 deletions

View file

@ -43,6 +43,7 @@ import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.logging.Logger;
/** /**
* A ControllerEnvironment represents a collection of controllers that are * A ControllerEnvironment represents a collection of controllers that are
@ -74,7 +75,7 @@ public abstract class ControllerEnvironment {
} }
static void log(String msg) { static void log(String msg) {
System.out.print(msg); Logger.getLogger(ControllerEnvironment.class.getName()).info(msg);
} }
/** /**

View file

@ -49,6 +49,8 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Logger;
import net.java.games.util.plugins.*; import net.java.games.util.plugins.*;
/** /**
@ -60,6 +62,8 @@ import net.java.games.util.plugins.*;
class DefaultControllerEnvironment extends ControllerEnvironment { class DefaultControllerEnvironment extends ControllerEnvironment {
static String libPath; static String libPath;
private static Logger log = Logger.getLogger(DefaultControllerEnvironment.class.getName());
/** /**
* Static utility method for loading native libraries. * Static utility method for loading native libraries.
* It will try to load from either the path given by * It will try to load from either the path given by
@ -138,12 +142,11 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
} else if(osName.equals("Windows 98") || osName.equals("Windows 2000")) { } else if(osName.equals("Windows 98") || osName.equals("Windows 2000")) {
pluginClasses = pluginClasses + " net.java.games.input.DirectInputEnvironmentPlugin"; pluginClasses = pluginClasses + " net.java.games.input.DirectInputEnvironmentPlugin";
} else if (osName.startsWith("Windows")) { } else if (osName.startsWith("Windows")) {
System.out.println("WARNING: Found unknown Windows version: " + osName); log.warning("Found unknown Windows version: " + osName);
System.out.println("Attempting to use default windows plug-in."); log.info("Attempting to use default windows plug-in.");
System.out.flush();
pluginClasses = pluginClasses + " net.java.games.input.DirectAndRawInputEnvironmentPlugin"; pluginClasses = pluginClasses + " net.java.games.input.DirectAndRawInputEnvironmentPlugin";
} else { } else {
System.out.println("Trying to use default plugin, OS name " + osName +" not recognised"); log.info("Trying to use default plugin, OS name " + osName +" not recognised");
} }
} }
@ -152,7 +155,7 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
String className = pluginClassTok.nextToken(); String className = pluginClassTok.nextToken();
try { try {
if(!loadedPlugins.contains(className)) { if(!loadedPlugins.contains(className)) {
System.out.println("Loading: " + className); log.info("Loading: " + className);
Class ceClass = Class.forName(className); Class ceClass = Class.forName(className);
ControllerEnvironment ce = (ControllerEnvironment) ceClass.newInstance(); ControllerEnvironment ce = (ControllerEnvironment) ceClass.newInstance();
if(ce.isSupported()) { if(ce.isSupported()) {

View file

@ -43,6 +43,7 @@ import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.Iterator; import java.util.Iterator;
import java.util.logging.Logger;
/** OSX HIDManager implementation /** OSX HIDManager implementation
* @author elias * @author elias
@ -50,6 +51,7 @@ import java.util.Iterator;
* @version 1.0 * @version 1.0
*/ */
final class OSXHIDDevice { final class OSXHIDDevice {
private final static Logger log = Logger.getLogger(OSXHIDDevice.class.getName());
private final static int AXIS_DEFAULT_MIN_VALUE = 0; private final static int AXIS_DEFAULT_MIN_VALUE = 0;
private final static int AXIS_DEFAULT_MAX_VALUE = 64*1024; private final static int AXIS_DEFAULT_MAX_VALUE = 64*1024;
@ -152,7 +154,7 @@ final class OSXHIDDevice {
int usage_page = getIntFromProperties(element_properties, kIOHIDElementUsagePageKey); int usage_page = getIntFromProperties(element_properties, kIOHIDElementUsagePageKey);
UsagePair usage_pair = createUsagePair(usage_page, usage); UsagePair usage_pair = createUsagePair(usage_page, usage);
if (usage_pair == null || (element_type != ElementType.INPUT_MISC && element_type != ElementType.INPUT_BUTTON && element_type != ElementType.INPUT_AXIS)) { if (usage_pair == null || (element_type != ElementType.INPUT_MISC && element_type != ElementType.INPUT_BUTTON && element_type != ElementType.INPUT_AXIS)) {
//System.out.println("element_type = 0x" + element_type + " | usage = " + usage + " | usage_page = " + usage_page); //log.info("element_type = 0x" + element_type + " | usage = " + usage + " | usage_page = " + usage_page);
return null; return null;
} else { } else {
return new OSXHIDElement(this, usage_pair, element_cookie, element_type, min, max, is_relative); return new OSXHIDElement(this, usage_pair, element_cookie, element_type, min, max, is_relative);
@ -238,17 +240,17 @@ final class OSXHIDDevice {
} }
*/ */
private final void dumpProperties() { private final void dumpProperties() {
System.out.println(toString()); log.info(toString());
dumpMap("", properties); dumpMap("", properties);
} }
private final static void dumpArray(String prefix, Object[] array) { private final static void dumpArray(String prefix, Object[] array) {
System.out.println(prefix + "{"); log.info(prefix + "{");
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
dumpObject(prefix + "\t", array[i]); dumpObject(prefix + "\t", array[i]);
System.out.println(prefix + ","); log.info(prefix + ",");
} }
System.out.println(prefix + "}"); log.info(prefix + "}");
} }
private final static void dumpMap(String prefix, Map map) { private final static void dumpMap(String prefix, Map map) {
@ -264,13 +266,13 @@ final class OSXHIDDevice {
private final static void dumpObject(String prefix, Object obj) { private final static void dumpObject(String prefix, Object obj) {
if (obj instanceof Long) { if (obj instanceof Long) {
Long l = (Long)obj; Long l = (Long)obj;
System.out.println(prefix + "0x" + Long.toHexString(l.longValue())); log.info(prefix + "0x" + Long.toHexString(l.longValue()));
} else if (obj instanceof Map) } else if (obj instanceof Map)
dumpMap(prefix, (Map)obj); dumpMap(prefix, (Map)obj);
else if (obj.getClass().isArray()) else if (obj.getClass().isArray())
dumpArray(prefix, (Object[])obj); dumpArray(prefix, (Object[])obj);
else else
System.out.println(prefix + obj); log.info(prefix + obj);
} }
private final Map getDeviceProperties() throws IOException { private final Map getDeviceProperties() throws IOException {

View file

@ -25,6 +25,8 @@
*/ */
package net.java.games.input; package net.java.games.input;
import java.util.logging.Logger;
/** /**
* Mapping utility class between native type ints and string names or * Mapping utility class between native type ints and string names or
* Key.Identifiers * Key.Identifiers
@ -32,6 +34,7 @@ package net.java.games.input;
*/ */
class LinuxNativeTypesMap { class LinuxNativeTypesMap {
private static LinuxNativeTypesMap INSTANCE = new LinuxNativeTypesMap(); private static LinuxNativeTypesMap INSTANCE = new LinuxNativeTypesMap();
private static Logger log = Logger.getLogger(LinuxNativeTypesMap.class.getName());
private final Component.Identifier relAxesIDs[]; private final Component.Identifier relAxesIDs[];
private final Component.Identifier absAxesIDs[]; private final Component.Identifier absAxesIDs[];
@ -755,7 +758,7 @@ class LinuxNativeTypesMap {
try { try {
retval = INSTANCE.relAxesIDs[nativeID]; retval = INSTANCE.relAxesIDs[nativeID];
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
System.out.println("INSTANCE.relAxesIDis only " + INSTANCE.relAxesIDs.length + " long, so " + nativeID + " not contained"); log.warn("INSTANCE.relAxesIDis only " + INSTANCE.relAxesIDs.length + " long, so " + nativeID + " not contained");
//ignore, pretend it was null //ignore, pretend it was null
} }
if(retval == null) { if(retval == null) {
@ -773,7 +776,7 @@ class LinuxNativeTypesMap {
try { try {
retval = INSTANCE.absAxesIDs[nativeID]; retval = INSTANCE.absAxesIDs[nativeID];
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
System.out.println("INSTANCE.absAxesIDs is only " + INSTANCE.absAxesIDs.length + " long, so " + nativeID + " not contained"); log.warn("INSTANCE.absAxesIDs is only " + INSTANCE.absAxesIDs.length + " long, so " + nativeID + " not contained");
//ignore, pretend it was null //ignore, pretend it was null
} }
if(retval == null) { if(retval == null) {
@ -791,7 +794,7 @@ class LinuxNativeTypesMap {
try { try {
retval = INSTANCE.buttonIDs[nativeID]; retval = INSTANCE.buttonIDs[nativeID];
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
System.out.println("INSTANCE.buttonIDs is only " + INSTANCE.buttonIDs.length + " long, so " + nativeID + " not contained"); log.warn("INSTANCE.buttonIDs is only " + INSTANCE.buttonIDs.length + " long, so " + nativeID + " not contained");
//ignore, pretend it was null //ignore, pretend it was null
} }
if(retval == null) { if(retval == null) {