fixed bug 403, added logging to tcp and email
[org.ibex.core.git] / src / org / ibex / Main.java
index 74b4b3f..bfc2abd 100644 (file)
@@ -3,6 +3,7 @@ package org.ibex;
 
 import java.net.*;
 import java.io.*;
+import java.util.*;
 import org.ibex.js.*;
 import org.ibex.util.*;
 
@@ -26,27 +27,41 @@ public class Main {
     public static Picture scarImage = null;
 
     public static void printUsage() {
-        System.err.println("Usage: ibex [-s] [-v] [-l <port>/<url>] source-location [initial-template]");
+        System.err.println("Usage: ibex [-lawp] [ url | file | directory ]");
         System.err.println("");
-        System.err.println("Options:");
-        System.err.println("    -v verbose logging (required for logging on Win32)");
-        System.err.println("    -s [not yet supported]");
-        System.err.println("    -l [not yet supported]");
-        System.err.println("");
-        System.err.println("Source-location is one of the following:");
-        System.err.println("    - the path to an xwar file");
-        System.err.println("    - the path to a directory to be used as an xwar");
-        System.err.println("    - the http url of an xwar");
-        System.err.println("");
-        System.err.println("Initial-template is the path of the template to load; defaults to 'main'");
+        System.err.println("    -l <level>      set logging level to { debug, info (default), warn, error, silent }");
+        System.err.println("    -l rpc          write log to a file on disk");
+        System.err.println("    -l user@host    email log to user@host");
+        System.err.println("    -l host:port    emit log to TCP socket");
+        System.err.println("    -l <file>       write log to a file on disk");
+        System.err.println("    -a              check assertions");
+        System.err.println("    -w <window-id>  reserved for libibex");
+        System.err.println("    -p              dump profiling information [not yet supported]");
         Runtime.getRuntime().exit(-1);
     }
 
-    public static void main(String[] args) throws UnknownHostException, JSExn {
+    public static void main(String[] args) throws UnknownHostException, JSExn, IOException {
         int startargs = 0;
         while (true) {
             if (startargs > args.length - 1) printUsage();
-            else if (args[startargs].equals("-v")) Log.verbose = true;
+            else if (args[startargs].equals("-a")) JS.checkAssertions = true;
+            else if (args[startargs].equals("-l")) {
+                startargs++;
+                StringTokenizer opts = new StringTokenizer(args[startargs], ",");
+                while(opts.hasMoreTokens()) {
+                    String opt = opts.nextToken();
+                    if (opt.indexOf('@') != -1) Log.email(opt);
+                    else if (opt.indexOf(':') != -1)
+                        Log.tcp(opt.substring(0, opt.indexOf(':')),
+                                Integer.parseInt(opt.substring(opt.indexOf(':') + 1)));
+                    else if (opt.equals("debug")) Log.level = Log.DEBUG;
+                    else if (opt.equals("info")) Log.level = Log.INFO;
+                    else if (opt.equals("warn")) Log.level = Log.WARN;
+                    else if (opt.equals("error")) Log.level = Log.ERROR;
+                    else if (opt.equals("error")) Log.level = Log.SILENT;
+                    else Log.file(opt);
+                }
+            }
             else break;
             startargs++;
         }
@@ -74,7 +89,6 @@ public class Main {
 
         if (Log.on) Log.info(Main.class, "loading xwar");
         final Ibex ibex = new Ibex(rr);
-        final JS final_rr = (JS)ibex.get("");
 
         scarImage =
             Picture.load((Stream)Main.builtin.get("org/ibex/builtin/scar.png"),