Using logger rather than System.err launcher
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 21 Dec 2012 12:49:27 +0100
branchlauncher
changeset 362a41b238056f4
parent 361 98eb1066dab1
child 363 8b59e6f8c837
Using logger rather than System.err
launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java
     1.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Fri Dec 21 09:18:52 2012 +0100
     1.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Fri Dec 21 12:49:27 2012 +0100
     1.3 @@ -34,6 +34,8 @@
     1.4  import java.util.Set;
     1.5  import java.util.concurrent.CountDownLatch;
     1.6  import java.util.concurrent.TimeUnit;
     1.7 +import java.util.logging.Level;
     1.8 +import java.util.logging.Logger;
     1.9  import javax.script.Invocable;
    1.10  import javax.script.ScriptEngine;
    1.11  import javax.script.ScriptEngineManager;
    1.12 @@ -54,6 +56,7 @@
    1.13   * execution engine.
    1.14   */
    1.15  public class Bck2BrwsrLauncher {
    1.16 +    private static final Logger LOG = Logger.getLogger(Bck2BrwsrLauncher.class.getName());
    1.17      private Set<ClassLoader> loaders = new LinkedHashSet<>();
    1.18      private List<MethodInvocation> methods = new ArrayList<>();
    1.19      private long timeOut;
    1.20 @@ -235,19 +238,19 @@
    1.21          int port = listener.getPort();
    1.22          
    1.23          URI uri = new URI("http://localhost:" + port + page);
    1.24 -        System.err.println("Showing " + uri);
    1.25 +        LOG.log(Level.INFO, "Showing {0}", uri);
    1.26          try {
    1.27              Desktop.getDesktop().browse(uri);
    1.28          } catch (UnsupportedOperationException ex) {
    1.29              String[] cmd = { 
    1.30                  "xdg-open", uri.toString()
    1.31              };
    1.32 -            System.err.println("Launching " + Arrays.toString(cmd));
    1.33 +            LOG.log(Level.INFO, "Launching {0}", Arrays.toString(cmd));
    1.34              final Process process = Runtime.getRuntime().exec(cmd);
    1.35              InputStream stdout = process.getInputStream();
    1.36              InputStream stderr = process.getErrorStream();
    1.37              int res = process.waitFor();
    1.38 -            System.err.println("Exit code: " + res);
    1.39 +            LOG.log(Level.INFO, "Exit code: {0}", res);
    1.40              drain("StdOut", stdout);
    1.41              drain("StdErr", stderr);
    1.42          }
    1.43 @@ -256,12 +259,13 @@
    1.44      private static void drain(String name, InputStream is) throws IOException {
    1.45          int av = is.available();
    1.46          if (av > 0) {
    1.47 -            System.err.println("v== " + name + " ==v");
    1.48 +            StringBuilder sb = new StringBuilder();
    1.49 +            sb.append("v== ").append(name).append(" ==v\n");
    1.50              while (av-- > 0) {
    1.51 -                System.err.write(is.read());
    1.52 +                sb.append((char)is.read());
    1.53              }
    1.54 -            System.err.println();
    1.55 -            System.err.println("^== " + name + " ==^");
    1.56 +            sb.append("\n^== ").append(name).append(" ==^");
    1.57 +            LOG.log(Level.INFO, sb.toString());
    1.58          }
    1.59      }
    1.60