< prev index next >

test/sun/rmi/runtime/Log/checkLogging/CheckLogging.java

Print this page


   1 /*
   2  * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  86         new ByteArrayOutputStream();
  87 
  88     private static final boolean usingOld =
  89         Boolean.getBoolean("sun.rmi.log.useOld");
  90 
  91     static {
  92         System.setProperty("sun.rmi.client.logCalls", "true");
  93         if (usingOld) {
  94             System.err.println("set default stream");
  95             LogStream.setDefaultStream(new PrintStream(clientCallOut));
  96         } else {
  97             logger = Logger.getLogger("sun.rmi.client.call");
  98             logger.addHandler(new InternalStreamHandler(clientCallOut));
  99         }
 100     }
 101 
 102     /* use registry to generate client & server call log info */
 103     private static Registry registry;
 104     static {
 105         try {
 106             registry = TestLibrary.createRegistryOnUnusedPort();
 107             REGISTRY_PORT = TestLibrary.getRegistryPort(registry);
 108             LOCATION = "rmi://localhost:" + REGISTRY_PORT + "/";
 109         } catch (Exception e) {
 110             TestLibrary.bomb("could not create registry");
 111         }
 112     }
 113 
 114     /**
 115      * Used to collect output from specific loggers
 116      */
 117     private static class InternalStreamHandler extends StreamHandler {
 118         private InternalStreamHandler(OutputStream out) {
 119             super(out, new SimpleFormatter());
 120             setLevel(Level.ALL);
 121         }
 122 
 123         public void publish(LogRecord record) {
 124             super.publish(record);
 125             flush();
 126         }


   1 /*
   2  * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  86         new ByteArrayOutputStream();
  87 
  88     private static final boolean usingOld =
  89         Boolean.getBoolean("sun.rmi.log.useOld");
  90 
  91     static {
  92         System.setProperty("sun.rmi.client.logCalls", "true");
  93         if (usingOld) {
  94             System.err.println("set default stream");
  95             LogStream.setDefaultStream(new PrintStream(clientCallOut));
  96         } else {
  97             logger = Logger.getLogger("sun.rmi.client.call");
  98             logger.addHandler(new InternalStreamHandler(clientCallOut));
  99         }
 100     }
 101 
 102     /* use registry to generate client & server call log info */
 103     private static Registry registry;
 104     static {
 105         try {
 106             registry = TestLibrary.createRegistryOnEphemeralPort();
 107             REGISTRY_PORT = TestLibrary.getRegistryPort(registry);
 108             LOCATION = "rmi://localhost:" + REGISTRY_PORT + "/";
 109         } catch (Exception e) {
 110             TestLibrary.bomb("could not create registry");
 111         }
 112     }
 113 
 114     /**
 115      * Used to collect output from specific loggers
 116      */
 117     private static class InternalStreamHandler extends StreamHandler {
 118         private InternalStreamHandler(OutputStream out) {
 119             super(out, new SimpleFormatter());
 120             setLevel(Level.ALL);
 121         }
 122 
 123         public void publish(LogRecord record) {
 124             super.publish(record);
 125             flush();
 126         }


< prev index next >