Hi Mark
The attached patch adds the OSM source file name into log messages so
if you are processing multiple files, you know which file each message
relates to.
There is a ThreadLocal class specially for keeping values on a per-thead
basis, as in the attached modification to your patch.
With your code there is a slight chance that there will be a problem if
a value is set at exactly the same time as the tag is being accessed.
..Steve
Index: src/uk/me/parabola/mkgmap/main/Main.java
===================================================================
--- src/uk/me/parabola/mkgmap/main/Main.java (revision 1491)
+++ src/uk/me/parabola/mkgmap/main/Main.java Sun Jan 24 15:41:42 GMT 2010
@@ -185,8 +185,10 @@
log.info("Submitting job " + filename);
FilenameTask task = new FilenameTask(new Callable<String>() {
public String call() {
+ log.tagThread(filename);
String output = mp.makeMap(args, filename);
log.debug("adding output name", output);
+ log.tagThread(null);
return output;
}
});
Index: src/uk/me/parabola/log/Logger.java
===================================================================
--- src/uk/me/parabola/log/Logger.java (revision 1497)
+++ src/uk/me/parabola/log/Logger.java Sun Jan 24 15:46:54 GMT 2010
@@ -36,6 +36,8 @@
public class Logger {
private final java.util.logging.Logger log;
+ private static final ThreadLocal<String> threadTags = new ThreadLocal<String>();
+
static {
initLogging();
}
@@ -150,7 +152,7 @@
*/
public void debug(Object o) {
if (log.isLoggable(Level.FINE))
- log.fine(o!=null? o.toString(): "null");
+ log.fine(tagMessage(o == null? "null" : o.toString()));
}
/**
@@ -169,7 +171,7 @@
public void info(Object o) {
if (log.isLoggable(Level.INFO))
- log.info(o.toString());
+ log.info(tagMessage(o == null? "null" : o.toString()));
}
public void info(Object ... olist) {
@@ -178,8 +180,7 @@
}
public void warn(Object o) {
- if (log.isLoggable(Level.WARNING))
- log.warning(o.toString());
+ log.warning(tagMessage(o == null? "null" : o.toString()));
}
public void warn(Object ... olist) {
@@ -188,16 +189,16 @@
}
public void error(Object o) {
- log.severe(o.toString());
+ log.severe(tagMessage(o == null? "null" : o.toString()));
}
public void error(Object o, Throwable e) {
- log.log(Level.SEVERE, o.toString(), e);
+ log.log(Level.SEVERE, tagMessage(o == null? "null" : o.toString()), e);
}
public void log(Level level, Object o) {
if (log.isLoggable(level))
- log.log(level, o.toString());
+ log.log(level, tagMessage(o == null? "null" : o.toString()));
}
public void log(Level level, Object ... olist) {
@@ -224,6 +225,15 @@
}
sb.setLength(sb.length()-1);
- log.log(type, sb.toString());
+ log.log(type, tagMessage(sb.toString()));
}
+
+ private String tagMessage(String message) {
+ String threadTag = threadTags.get();
+ return (threadTag != null) ? threadTag + ": " + message : message;
-}
+ }
+
+ public void tagThread(String tag) {
+ threadTags.set(tag);
+ }
+}
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev