Changeset 88 for bbtracker/trunk/src/org/bbtracker/mobile/BBTracker.java
- Timestamp:
- 08/23/07 22:15:34 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
bbtracker/trunk/src/org/bbtracker/mobile/BBTracker.java
r75 r88 18 18 package org.bbtracker.mobile; 19 19 20 import java.io.OutputStream; 21 import java.io.PrintStream; 22 import java.util.Date; 20 23 import java.util.Timer; 21 24 25 import javax.microedition.io.Connector; 26 import javax.microedition.io.file.FileConnection; 22 27 import javax.microedition.lcdui.Alert; 23 28 import javax.microedition.lcdui.AlertType; … … 34 39 import org.bbtracker.mobile.TrackStore.TrackStoreException; 35 40 import org.bbtracker.mobile.gui.MainCanvas; 41 import org.bbtracker.mobile.gui.OptionsForm; 36 42 import org.bbtracker.mobile.gui.TrackNameForm; 37 import org.bbtracker.mobile.gui.OptionsForm;38 43 import org.bbtracker.mobile.gui.TracksForm; 39 44 … … 46 51 47 52 private static BBTracker instance; 53 54 private static PrintStream logStream; 48 55 49 56 private final TrackManager trackManager; … … 80 87 nonFatal(e, "Initializing Location Provider", mainCanvas); 81 88 } 89 90 initLog(); 82 91 } 83 92 84 93 public void shutdown(final boolean destroy) { 94 log(this, "shutdown " + destroy); 85 95 if (trackManager != null) { 86 96 trackManager.shutdown(); … … 94 104 notifyDestroyed(); 95 105 } 106 if (logStream != null) { 107 logStream.close(); 108 logStream = null; 109 } 96 110 } 97 111 … … 121 135 122 136 public static void nonFatal(final Throwable t, final String action, final Displayable next) { 123 log( t);137 log(BBTracker.class, t, "non-fatal " + action); 124 138 final Alert alert = new Alert("Non-fatal Exception", "Non-fatal Exception while " + action + ": " + 125 139 t.getMessage(), null, AlertType.WARNING); … … 128 142 129 143 public static void fatal(final Throwable t, final String action) { 130 log( t);144 log(BBTracker.class, t, "fatal " + action); 131 145 final BBTracker i = getInstance(); 132 146 i.shutdown(false); … … 152 166 } 153 167 154 public static void log(final Throwable e) { 168 public static void initLog() { 169 if (logStream != null) { 170 return; 171 } 172 final String dirName = Preferences.getInstance().getTrackDirectory(); 173 final String logUrl = "file:///" + dirName + "debug.txt"; 174 try { 175 final FileConnection fileConnection = (FileConnection) Connector.open(logUrl); 176 if (!(fileConnection.exists() && fileConnection.canWrite())) { 177 fileConnection.close(); 178 return; 179 } 180 final OutputStream out = fileConnection.openOutputStream(); 181 logStream = new PrintStream(out); 182 } catch (final Throwable e) { 183 log(BBTracker.class, e, "opening " + logUrl); 184 } 185 } 186 187 public static void setLogActive(final boolean logActive) { 188 if (!logActive && logStream != null) { 189 logStream.close(); 190 logStream = null; 191 } 192 193 final String dirName = Preferences.getInstance().getTrackDirectory(); 194 final String logUrl = "file:///" + dirName + "debug.txt"; 195 try { 196 final FileConnection fileConnection = (FileConnection) Connector.open(logUrl); 197 if (logActive) { 198 if (!fileConnection.exists()) { 199 fileConnection.create(); 200 } 201 final OutputStream out = fileConnection.openOutputStream(); 202 logStream = new PrintStream(out); 203 } else { 204 if (fileConnection.exists()) { 205 fileConnection.delete(); 206 fileConnection.close(); 207 } 208 } 209 } catch (final Throwable e) { 210 log(BBTracker.class, e, "opening " + logUrl); 211 } 212 } 213 214 public static boolean isLogActive() { 215 return logStream != null; 216 } 217 218 public static void log(final Object source, final Throwable e) { 219 log(source, "Exception: " + e.toString()); 220 // this is only useful for debugging in the emulator 155 221 e.printStackTrace(); 156 222 } 157 223 158 public static void log(final String m) { 159 System.err.println(m); 224 public static void log(final Object source, final Throwable e, final String message) { 225 log(source, "Exception <" + message + ">: " + e.toString()); 226 // this is only useful for debugging in the emulator 227 e.printStackTrace(); 228 } 229 230 public static void log(final Object source, final String m) { 231 final String line = new Date() + ": [" + source + "] " + m; 232 System.err.println(line); 233 if (logStream != null) { 234 logStream.println(line); 235 } 160 236 } 161 237 … … 165 241 166 242 protected void pauseApp() { 243 log(this, "pauseApp"); 167 244 } 168 245 169 246 protected void startApp() throws MIDletStateChangeException { 247 log(this, firstStart ? "first startApp" : "startApp"); 170 248 if (firstStart) { 171 249 firstStart = false;
Note: See TracChangeset
for help on using the changeset viewer.