Switch to new logging API.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@510 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Michael Bayne
2008-05-27 22:55:10 +00:00
parent b521b4bfbf
commit e00b4ddd6b
108 changed files with 497 additions and 605 deletions
@@ -38,6 +38,8 @@ import com.samskivert.util.StringUtil;
import org.apache.commons.io.IOUtils;
import static com.threerings.resource.Log.log;
/**
* A resource bundle provides access to the resources in a jar file.
*/
@@ -135,16 +137,16 @@ public class FileResourceBundle extends ResourceBundle
try {
resolveJarFile();
} catch (IOException ioe) {
Log.warning("Failure resolving jar file '" + _source +
log.warning("Failure resolving jar file '" + _source +
"': " + ioe + ".");
wipeBundle(true);
return false;
}
Log.info("Unpacking into " + _cache + "...");
log.info("Unpacking into " + _cache + "...");
if (!_cache.exists()) {
if (!_cache.mkdir()) {
Log.warning("Failed to create bundle cache directory '" +
log.warning("Failed to create bundle cache directory '" +
_cache + "'.");
closeJar();
// we are hopelessly fucked
@@ -166,11 +168,11 @@ public class FileResourceBundle extends ResourceBundle
try {
_unpacked.createNewFile();
if (!_unpacked.setLastModified(_sourceLastMod)) {
Log.warning("Failed to set last mod on stamp file '" +
log.warning("Failed to set last mod on stamp file '" +
_unpacked + "'.");
}
} catch (IOException ioe) {
Log.warning("Failure creating stamp file '" + _unpacked +
log.warning("Failure creating stamp file '" + _unpacked +
"': " + ioe + ".");
// no need to stick a fork in things at this point
}
@@ -200,14 +202,14 @@ public class FileResourceBundle extends ResourceBundle
// that we ensure that it is revalidated
File vfile = new File(FileUtil.resuffix(_source, ".jar", ".jarv"));
if (vfile.exists() && !vfile.delete()) {
Log.warning("Failed to delete " + vfile + ".");
log.warning("Failed to delete " + vfile + ".");
}
// close and delete our source jar file
if (deleteJar && _source != null) {
closeJar();
if (!_source.delete()) {
Log.warning("Failed to delete " + _source +
log.warning("Failed to delete " + _source +
" [exists=" + _source.exists() + "].");
}
}
@@ -329,8 +331,7 @@ public class FileResourceBundle extends ResourceBundle
} catch (IOException ioe) {
String msg = "Failed to resolve resource bundle jar file '" +
_source + "'";
Log.warning(msg + ".");
Log.logStackTrace(ioe);
log.warning(msg + ".", ioe);
throw (IOException) new IOException(msg).initCause(ioe);
}
}
@@ -345,7 +346,7 @@ public class FileResourceBundle extends ResourceBundle
_jarSource.close();
}
} catch (Exception ioe) {
Log.warning("Failed to close jar file [path=" + _source +
log.warning("Failed to close jar file [path=" + _source +
", error=" + ioe + "].");
}
}
@@ -358,7 +359,7 @@ public class FileResourceBundle extends ResourceBundle
if (_tmpdir == null) {
String tmpdir = System.getProperty("java.io.tmpdir");
if (tmpdir == null) {
Log.info("No system defined temp directory. Faking it.");
log.info("No system defined temp directory. Faking it.");
tmpdir = System.getProperty("user.home");
}
setCacheDir(new File(tmpdir));
@@ -375,16 +376,16 @@ public class FileResourceBundle extends ResourceBundle
_tmpdir = new File(tmpdir, "narcache_" + rando);
if (!_tmpdir.exists()) {
if (_tmpdir.mkdirs()) {
Log.debug("Created narya temp cache directory '" + _tmpdir + "'.");
log.debug("Created narya temp cache directory '" + _tmpdir + "'.");
} else {
Log.warning("Failed to create temp cache directory '" + _tmpdir + "'.");
log.warning("Failed to create temp cache directory '" + _tmpdir + "'.");
}
}
// add a hook to blow away the temp directory when we exit
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run () {
Log.info("Clearing narya temp cache '" + _tmpdir + "'.");
log.info("Clearing narya temp cache '" + _tmpdir + "'.");
FileUtil.recursiveDelete(_tmpdir);
}
});
@@ -43,6 +43,8 @@ import com.samskivert.util.StringUtil;
import com.threerings.geom.GeomUtil;
import static com.threerings.resource.Log.log;
/**
* This class is not used directly, except by a registering ResourceManager
* so that we can load data from the resource manager using URLs of the form
@@ -105,7 +107,7 @@ public class Handler extends URLStreamHandler
this.connected = true;
} catch (IOException ioe) {
Log.warning("Could not find resource [url=" + this.url +
log.warning("Could not find resource [url=" + this.url +
", error=" + ioe.getMessage() + "].");
throw ioe; // rethrow
}
@@ -144,7 +146,7 @@ public class Handler extends URLStreamHandler
{
// we can only do this with PNGs
if (!path.endsWith(".png")) {
Log.warning("Requested sub-tile of non-PNG resource " +
log.warning("Requested sub-tile of non-PNG resource " +
"[bundle=" + bundle + ", path=" + path +
", dims=" + query + "].");
return _rmgr.getResource(bundle, path);
@@ -166,7 +168,7 @@ public class Handler extends URLStreamHandler
} catch (NumberFormatException nfe) {
}
if (width <= 0 || height <= 0 || tidx < 0) {
Log.warning("Bogus sub-image dimensions [bundle=" + bundle +
log.warning("Bogus sub-image dimensions [bundle=" + bundle +
", path=" + path + ", dims=" + query + "].");
throw new FileNotFoundException(path);
}
+4 -28
View File
@@ -21,36 +21,12 @@
package com.threerings.resource;
import com.samskivert.util.Logger;
/**
* A placeholder class that contains a reference to the log object used by
* the resource management package.
* Contains a reference to the log object used by the resource management package.
*/
public class Log
{
public static com.samskivert.util.Log log =
new com.samskivert.util.Log("resource");
/** Convenience function. */
public static void debug (String message)
{
log.debug(message);
}
/** Convenience function. */
public static void info (String message)
{
log.info(message);
}
/** Convenience function. */
public static void warning (String message)
{
log.warning(message);
}
/** Convenience function. */
public static void logStackTrace (Throwable t)
{
log.logStackTrace(com.samskivert.util.Log.WARNING, t);
}
public static Logger log = Logger.getLogger("com.threerings.resource");
}
@@ -30,6 +30,8 @@ import java.net.URL;
import java.security.AccessControlException;
import java.util.HashSet;
import static com.threerings.resource.Log.log;
/**
* Resource bundle that retrieves its contents via HTTP over the network from a root URL.
*/
@@ -48,7 +50,7 @@ public class NetworkResourceBundle extends ResourceBundle
try {
_bundleURL = new URL(root + path);
} catch (MalformedURLException mue) {
Log.warning("Created malformed URL for resource. [root=" + root + ", path=" + path);
log.warning("Created malformed URL for resource. [root=" + root + ", path=" + path);
}
_ident = path;
@@ -75,7 +77,7 @@ public class NetworkResourceBundle extends ResourceBundle
try {
ucon = (HttpURLConnection) resourceUrl.openConnection();
} catch (IOException ioe) {
Log.warning("Unable to open connection [url=" + resourceUrl + ", ex=" + ioe + "]");
log.warning("Unable to open connection [url=" + resourceUrl + ", ex=" + ioe + "]");
}
if (ucon == null) {
@@ -85,10 +87,10 @@ public class NetworkResourceBundle extends ResourceBundle
ucon.connect();
return ucon.getInputStream();
} catch (IOException ioe) {
Log.warning("Unable to open input stream [url=" + resourceUrl + ", ex=" + ioe + "]");
log.warning("Unable to open input stream [url=" + resourceUrl + ", ex=" + ioe + "]");
return null;
} catch (AccessControlException ace) {
Log.warning("Unable to connect due to access permissions [url=" + resourceUrl + "]");
log.warning("Unable to connect due to access permissions [url=" + resourceUrl + "]");
throw ace;
}
}
@@ -57,6 +57,8 @@ import com.samskivert.net.PathUtil;
import com.samskivert.util.ResultListener;
import com.samskivert.util.StringUtil;
import static com.threerings.resource.Log.log;
/**
* The resource manager is responsible for maintaining a repository of resources that are
* synchronized with a remote source. This is accomplished in the form of sets of jar files
@@ -217,7 +219,7 @@ public class ResourceManager
}
});
} catch (SecurityException se) {
Log.info("Running in sandbox. Unable to bind rsrc:// handler.");
log.info("Running in sandbox. Unable to bind rsrc:// handler.");
}
}
@@ -314,7 +316,7 @@ public class ResourceManager
try {
initObs.wait();
} catch (InterruptedException ie) {
Log.warning("Interrupted while waiting for bundles to unpack.");
log.warning("Interrupted while waiting for bundles to unpack.");
}
}
}
@@ -678,8 +680,7 @@ public class ResourceManager
} catch (Exception e) {
String errmsg = "Unable to load resource manager config [rdir=" + _rdir +
", cpath=" + configPath + "]";
Log.warning(errmsg + ".");
Log.logStackTrace(e);
log.warning(errmsg + ".", e);
throw new IOException(errmsg);
}
return config;
@@ -776,8 +777,7 @@ public class ResourceManager
// there's no way to find out if it's already closed or not, so we have to check
// the exception message to determine if this is actually warning worthy
if (!"closed".equals(ioe.getMessage())) {
Log.warning("Failure closing image input '" + iis + "'.");
Log.logStackTrace(ioe);
log.warning("Failure closing image input '" + iis + "'.", ioe);
}
}
}
@@ -797,7 +797,7 @@ public class ResourceManager
if (!m.matches()) {
// if we can't parse the java version we're in weird land and should probably just try
// our luck with what we've got rather than try to download a new jvm
Log.warning("Unable to parse VM version, hoping for the best [version=" + verstr + "]");
log.warning("Unable to parse VM version, hoping for the best [version=" + verstr + "]");
return 0;
}
@@ -829,7 +829,7 @@ public class ResourceManager
for (ResourceBundle bundle : _bundles) {
if (bundle instanceof FileResourceBundle &&
!((FileResourceBundle)bundle).sourceIsReady()) {
Log.warning("Bundle failed to initialize " + bundle + ".");
log.warning("Bundle failed to initialize " + bundle + ".");
}
if (_obs != null) {
int pct = count*100/_bundles.size();