示例#1
0
 public static final ResultLogger getLogger() {
   if (logger == null) {
     log.warn(LOG_TAG, "In-memory logging only (log database options were not set?)");
     logger = new InMemoryLogger();
   }
   return logger;
 }
示例#2
0
 public static void exec(Runnable toRun, String[] args, boolean exit, LogInterface logInterface) {
   // --Init
   log = logInterface;
   // (cleanup)
   ignoredClasspath = new String[0];
   runName = "<unnamed>";
   outputDB = null;
   dataDB = null;
   execDir = null;
   logger = null;
   // (bootstrap)
   Map<String, String> options = parseOptions(args); // get options
   fillOptions(BOOTSTRAP_CLASSES, options, false); // bootstrap
   log.bootstrap();
   log.startTrack("init");
   // (fill options)
   Class<?>[] visibleClasses = getVisibleClasses(options); // get classes
   Map<String, Field> optionFields = fillOptions(visibleClasses, options); // fill
   try {
     initDatabase(visibleClasses, options, optionFields); // database
   } catch (DatabaseException e) {
     log.warn(LOG_TAG, e.getMessage());
   }
   dumpOptions(options); // file dump
   log.endTrack("init");
   log.setup();
   // --Run Program
   try {
     log.startTrack("main");
     toRun.run();
     log.endTrack("main"); // ends main
     log.startTrack("flushing");
     if (logger != null) {
       logger.save();
     }
   } catch (Throwable e) { // catch everything
     log.exception(e);
     System.err.flush();
     if (logger != null) {
       exitMessage = e.getClass().getName() + ": " + e.getMessage();
       logger.suggestFlush(); // not a save!
     }
     log.exit(ExitCode.FATAL_EXCEPTION);
   }
   log.endTrack("flushing");
   if (exit) {
     log.exit(ExitCode.OK); // soft exit
   }
 }
示例#3
0
 private static final void dumpOptions(Map<String, String> options) {
   StringBuilder b = new StringBuilder();
   for (String key : options.keySet()) {
     b.append("--").append(key).append(" \"").append(options.get(key)).append("\" \\\n");
   }
   try {
     File f = touch("options");
     if (f != null) {
       FileWriter w = new FileWriter(f);
       w.write(b.toString());
       w.close();
     }
   } catch (IOException e) {
     log.warn(LOG_TAG, "Could not write options file");
   }
 }