Update osmand.log configuration - part of working dir

This commit is contained in:
Victor Shcherb 2011-12-26 14:29:34 +01:00
parent 0a53e6c321
commit 384843c896
4 changed files with 39 additions and 18 deletions

View file

@ -12,5 +12,5 @@
</listAttribute> </listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="net.osmand.swing.OsmExtractionUI"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="net.osmand.swing.OsmExtractionUI"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="DataExtractionOSM"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="DataExtractionOSM"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XX:+UseParallelGC -Xmx1300M -Xmn256M"/> <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XX:+UseParallelGC -Xmx1300M -Xmn256M -Djava.util.logging.config.file=logging.properties"/>
</launchConfiguration> </launchConfiguration>

View file

@ -4,10 +4,11 @@ handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler
# Set the default logging level for the logger named com.mycompany # Set the default logging level for the logger named com.mycompany
net.osmand.level = ALL net.osmand.level = ALL
java.util.logging.FileHandler.pattern=%h/Application Data/Osmand/osmand.log # configured in java code (In working dir) by default %h/Osmand/osmand.log
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter # java.util.logging.FileHandler.pattern=%h/Application Data/Osmand/osmand.log
java.util.logging.FileHandler.append = true #java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.limit = 5000000 #java.util.logging.FileHandler.append = true
#java.util.logging.FileHandler.limit = 5000000
java.util.logging.ConsoleHandler.level=ALL java.util.logging.ConsoleHandler.level=ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

View file

@ -41,6 +41,7 @@ import net.osmand.data.preparation.IndexCreator;
import net.osmand.data.preparation.MapZooms; import net.osmand.data.preparation.MapZooms;
import net.osmand.impl.ConsoleProgressImplementation; import net.osmand.impl.ConsoleProgressImplementation;
import net.osmand.osm.MapRenderingTypes; import net.osmand.osm.MapRenderingTypes;
import net.osmand.swing.OsmExtractionUI;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -111,6 +112,7 @@ public class IndexBatchCreator {
public static void main(String[] args) { public static void main(String[] args) {
IndexBatchCreator creator = new IndexBatchCreator(); IndexBatchCreator creator = new IndexBatchCreator();
OsmExtractionUI.configLogFile();
if(args == null || args.length == 0){ if(args == null || args.length == 0){
System.out.println("Please specify -local parameter or path to batch.xml configuration file as 1 argument."); System.out.println("Please specify -local parameter or path to batch.xml configuration file as 1 argument.");
throw new IllegalArgumentException("Please specify -local parameter or path to batch.xml configuration file as 1 argument."); throw new IllegalArgumentException("Please specify -local parameter or path to batch.xml configuration file as 1 argument.");

View file

@ -15,6 +15,9 @@ import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.logging.FileHandler;
import java.util.logging.LogManager;
import java.util.logging.SimpleFormatter;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
@ -58,26 +61,28 @@ import rtree.RTree;
public class OsmExtractionUI implements IMapLocationListener { public class OsmExtractionUI implements IMapLocationListener {
private static final Log log = LogFactory.getLog(OsmExtractionUI.class); private static final Log log = LogFactory.getLog(OsmExtractionUI.class);
public static final String LOG_PATH = getUserLogDirectoryPath() + "/Osmand/osmand.log"; //$NON-NLS-1$ //$NON-NLS-2$ public static final String LOG_PATH = getUserLogDirectoryPath() + "/osmand.log"; //$NON-NLS-1$ //$NON-NLS-2$
public static OsmExtractionUI MAIN_APP; public static OsmExtractionUI MAIN_APP;
public static String getUserLogDirectoryPath() { public static String getUserLogDirectoryPath() {
String path = null; return DataExtractionSettings.getSettings().getDefaultWorkingDir().getAbsolutePath();
if (System.getProperty("os.name").startsWith("Windows")) { // String path = null;
path = System.getenv("APPDATA").replaceAll("\\\\", "/"); // if (System.getProperty("os.name").startsWith("Windows")) {
} else if (System.getProperty("os.name").startsWith("Mac")) { // path = System.getenv("APPDATA").replaceAll("\\\\", "/");
path = System.getProperty("user.home") + "/Library/Logs"; // } else if (System.getProperty("os.name").startsWith("Mac")) {
} else if (System.getenv("XDG_CACHE_HOME") != null) { // path = System.getProperty("user.home") + "/Library/Logs";
path = System.getenv("XDG_CACHE_HOME"); // } else if (System.getenv("XDG_CACHE_HOME") != null) {
} else { // path = System.getenv("XDG_CACHE_HOME");
path = System.getProperty("user.home") + "/.cache"; // } else {
} // path = System.getProperty("user.home") + "/.cache";
return path; // }
// return path;
} }
public static void main(String[] args) { public static void main(String[] args) {
// first of all config log // first of all config log
new File(LOG_PATH).getParentFile().mkdirs(); configLogFile();
final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(){ Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(){
@Override @Override
@ -94,6 +99,19 @@ public class OsmExtractionUI implements IMapLocationListener {
MAIN_APP.frame.setVisible(true); MAIN_APP.frame.setVisible(true);
} }
public static void configLogFile() {
new File(LOG_PATH).getParentFile().mkdirs();
try {
FileHandler fh = new FileHandler(LOG_PATH, 5000000, 1, true);
fh.setFormatter(new SimpleFormatter());
LogManager.getLogManager().getLogger("").addHandler(fh);
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}