src/share/classes/java/rmi/server/LogStream.java

Print this page




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.rmi.server;
  26 
  27 import java.io.*;
  28 import java.util.*;
  29 
  30 /**
  31  * <code>LogStream</code> provides a mechanism for logging errors that are
  32  * of possible interest to those monitoring a system.
  33  *
  34  * @author  Ann Wollrath (lots of code stolen from Ken Arnold)
  35  * @since   JDK1.1
  36  * @deprecated no replacement
  37  */
  38 @Deprecated
  39 public class LogStream extends PrintStream {
  40 
  41     /** table mapping known log names to log stream objects */
  42     private static Hashtable    known = new Hashtable(5);
  43     /** default output stream for new logs */
  44     private static PrintStream  defaultStream = System.err;
  45 
  46     /** log name for this log */
  47     private String name;
  48 
  49     /** stream where output of this log is sent to */
  50     private OutputStream logOut;
  51 
  52     /** string writer for writing message prefixes to log stream */
  53     private OutputStreamWriter logWriter;
  54 
  55     /** string buffer used for constructing log message prefixes */
  56     private StringBuffer buffer = new StringBuffer();
  57 
  58     /** stream used for buffering lines */
  59     private ByteArrayOutputStream bufOut;
  60 
  61     /**
  62      * Create a new LogStream object.  Since this only constructor is


  73         super(new ByteArrayOutputStream());
  74         bufOut = (ByteArrayOutputStream) super.out;
  75 
  76         this.name = name;
  77         setOutputStream(out);
  78     }
  79 
  80     /**
  81      * Return the LogStream identified by the given name.  If
  82      * a log corresponding to "name" does not exist, a log using
  83      * the default stream is created.
  84      * @param name name identifying the desired LogStream
  85      * @return log associated with given name
  86      * @since JDK1.1
  87      * @deprecated no replacement
  88      */
  89     @Deprecated
  90     public static LogStream log(String name) {
  91         LogStream stream;
  92         synchronized (known) {
  93             stream = (LogStream)known.get(name);
  94             if (stream == null) {
  95                 stream = new LogStream(name, defaultStream);
  96             }
  97             known.put(name, stream);
  98         }
  99         return stream;
 100     }
 101 
 102     /**
 103      * Return the current default stream for new logs.
 104      * @return default log stream
 105      * @see #setDefaultStream
 106      * @since JDK1.1
 107      * @deprecated no replacement
 108      */
 109     @Deprecated
 110     public static synchronized PrintStream getDefaultStream() {
 111         return defaultStream;
 112     }
 113 




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.rmi.server;
  26 
  27 import java.io.*;
  28 import java.util.*;
  29 
  30 /**
  31  * <code>LogStream</code> provides a mechanism for logging errors that are
  32  * of possible interest to those monitoring a system.
  33  *
  34  * @author  Ann Wollrath (lots of code stolen from Ken Arnold)
  35  * @since   JDK1.1
  36  * @deprecated no replacement
  37  */
  38 @Deprecated
  39 public class LogStream extends PrintStream {
  40 
  41     /** table mapping known log names to log stream objects */
  42     private static Map<String,LogStream> known = new HashMap<>(5);
  43     /** default output stream for new logs */
  44     private static PrintStream  defaultStream = System.err;
  45 
  46     /** log name for this log */
  47     private String name;
  48 
  49     /** stream where output of this log is sent to */
  50     private OutputStream logOut;
  51 
  52     /** string writer for writing message prefixes to log stream */
  53     private OutputStreamWriter logWriter;
  54 
  55     /** string buffer used for constructing log message prefixes */
  56     private StringBuffer buffer = new StringBuffer();
  57 
  58     /** stream used for buffering lines */
  59     private ByteArrayOutputStream bufOut;
  60 
  61     /**
  62      * Create a new LogStream object.  Since this only constructor is


  73         super(new ByteArrayOutputStream());
  74         bufOut = (ByteArrayOutputStream) super.out;
  75 
  76         this.name = name;
  77         setOutputStream(out);
  78     }
  79 
  80     /**
  81      * Return the LogStream identified by the given name.  If
  82      * a log corresponding to "name" does not exist, a log using
  83      * the default stream is created.
  84      * @param name name identifying the desired LogStream
  85      * @return log associated with given name
  86      * @since JDK1.1
  87      * @deprecated no replacement
  88      */
  89     @Deprecated
  90     public static LogStream log(String name) {
  91         LogStream stream;
  92         synchronized (known) {
  93             stream = known.get(name);
  94             if (stream == null) {
  95                 stream = new LogStream(name, defaultStream);
  96             }
  97             known.put(name, stream);
  98         }
  99         return stream;
 100     }
 101 
 102     /**
 103      * Return the current default stream for new logs.
 104      * @return default log stream
 105      * @see #setDefaultStream
 106      * @since JDK1.1
 107      * @deprecated no replacement
 108      */
 109     @Deprecated
 110     public static synchronized PrintStream getDefaultStream() {
 111         return defaultStream;
 112     }
 113