com.caucho.log
Class EnvironmentStream

java.lang.Object
  extended by com.caucho.vfs.StreamImpl
      extended by com.caucho.log.EnvironmentStream

public class EnvironmentStream
extends StreamImpl

A stream that varies depending on the environment class loader.


Field Summary
 
Fields inherited from class com.caucho.vfs.StreamImpl
_nullPath, _path
 
Constructor Summary
EnvironmentStream(java.io.OutputStream defaultStream)
          Create the environment stream.
EnvironmentStream(java.lang.String envVariable, java.io.OutputStream defaultStream)
          Create the environment stream.
 
Method Summary
 boolean canWrite()
          True if the stream can write
 void close()
          Flush data to the stream.
 void flush()
          Flush data to the stream.
 java.io.OutputStream getGlobalStream()
          Returns the global stream
static WriteStream getOriginalSystemErr()
          Returns the original System.out writer
static WriteStream getOriginalSystemOut()
          Returns the original System.out writer
static EnvironmentStream getStderr()
          Returns the environment stream for System.err
static EnvironmentStream getStdout()
          Returns the environment stream for System.out
 java.io.OutputStream getStream()
          Returns the global stream
 java.lang.String getVariable()
          Returns the context stream's variable.
static void logStderr(java.lang.String msg)
          Logs a message to the original stderr in cases where java.util.logging is dangerous, e.g.
static void logStderr(java.lang.String msg, java.lang.Throwable e)
          Logs a message to the original stderr in cases where java.util.logging is dangerous, e.g.
 java.lang.Object setGlobalStream(java.io.OutputStream defaultStream)
          Returns the context stream's variable.
static void setStderr(java.io.OutputStream os)
          Sets path as the backing stream for System.err
static void setStdout(java.io.OutputStream os)
          Sets the backing stream for System.out
 java.lang.Object setStream(java.io.OutputStream os)
          Returns the context stream's variable.
 void write(byte[] buf, int offset, int length, boolean isEnd)
          Write data to the stream.
 
Methods inherited from class com.caucho.vfs.StreamImpl
canRead, clearWrite, closeWrite, flushBuffer, flushToDisk, getAttribute, getAttributeNames, getAvailable, getFlushOnNewline, getNewline, getPath, getReadBuffer, getReadPosition, hasSkip, isClosed, isEof, read, readNonBlock, readTimeout, removeAttribute, seekEnd, seekStart, setAttribute, setPath, setWriteEncoding, skip, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnvironmentStream

public EnvironmentStream(java.lang.String envVariable,
                         java.io.OutputStream defaultStream)
Create the environment stream.

Parameters:
envVariable - the variable for the underlying stream
defaultStream - the stream used if outside an environment

EnvironmentStream

public EnvironmentStream(java.io.OutputStream defaultStream)
Create the environment stream.

Parameters:
defaultStream - the stream used if outside an environment
Method Detail

getVariable

public java.lang.String getVariable()
Returns the context stream's variable.


getGlobalStream

public java.io.OutputStream getGlobalStream()
Returns the global stream


setGlobalStream

public java.lang.Object setGlobalStream(java.io.OutputStream defaultStream)
Returns the context stream's variable.


getStream

public java.io.OutputStream getStream()
Returns the global stream


setStream

public java.lang.Object setStream(java.io.OutputStream os)
Returns the context stream's variable.


canWrite

public boolean canWrite()
True if the stream can write

Overrides:
canWrite in class StreamImpl

write

public void write(byte[] buf,
                  int offset,
                  int length,
                  boolean isEnd)
           throws java.io.IOException
Write data to the stream.

Overrides:
write in class StreamImpl
Parameters:
buf - the byte array to write.
offset - the offset into the byte array.
length - the number of bytes to write.
isEnd - true when the write is flushing a close.
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flush data to the stream.

Overrides:
flush in class StreamImpl
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Flush data to the stream.

Overrides:
close in class StreamImpl
Throws:
java.io.IOException

setStdout

public static void setStdout(java.io.OutputStream os)
Sets the backing stream for System.out


getStdout

public static EnvironmentStream getStdout()
Returns the environment stream for System.out


getOriginalSystemOut

public static WriteStream getOriginalSystemOut()
Returns the original System.out writer


setStderr

public static void setStderr(java.io.OutputStream os)
Sets path as the backing stream for System.err


getStderr

public static EnvironmentStream getStderr()
Returns the environment stream for System.err


getOriginalSystemErr

public static WriteStream getOriginalSystemErr()
Returns the original System.out writer


logStderr

public static void logStderr(java.lang.String msg,
                             java.lang.Throwable e)
Logs a message to the original stderr in cases where java.util.logging is dangerous, e.g. in the logging code itself.


logStderr

public static void logStderr(java.lang.String msg)
Logs a message to the original stderr in cases where java.util.logging is dangerous, e.g. in the logging code itself.