Package com.atlassian.confluence.logging
Class LoggingOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.atlassian.confluence.logging.LoggingOutputStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public class LoggingOutputStream extends OutputStream
Output stream that redirects all writes to provided logger. Useful with legacy code that expects PrintStream as logging facility.Example:
// Create PrintStream with autoFlush=true, otherwise // LoggingOutputStream will accumulate bytes until closed. System.setErr(new PrintStream( new LoggingOutputStream( Logger.getLogger("outLog"), Level.ERROR), true));
-
-
Constructor Summary
Constructors Constructor Description LoggingOutputStream(org.apache.log4j.Logger log, org.apache.log4j.Level level)
Creates the Logging instance to flush to the given logger.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this output stream and releases any system resources associated with this stream.void
flush()
Flushes this output stream and forces any buffered output bytes to be written out.protected String
processLine(String s)
Examines an inout line and amends, if needed.void
write(int b)
Writes the specified byte to this output stream.-
Methods inherited from class java.io.OutputStream
nullOutputStream, write, write
-
-
-
-
Constructor Detail
-
LoggingOutputStream
public LoggingOutputStream(@Nonnull org.apache.log4j.Logger log, @Nonnull org.apache.log4j.Level level)
Creates the Logging instance to flush to the given logger.- Parameters:
log
- the Logger to write tolevel
- the log level- Throws:
NullPointerException
- in case if one of arguments is null.
-
-
Method Detail
-
write
public void write(int b) throws IOException
Writes the specified byte to this output stream.- Specified by:
write
in classOutputStream
- Parameters:
b
- the byte to write- Throws:
IOException
- if an I/O error occurs.
-
flush
public void flush()
Flushes this output stream and forces any buffered output bytes to be written out.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
-
close
public void close()
Closes this output stream and releases any system resources associated with this stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
-
processLine
protected String processLine(String s)
Examines an inout line and amends, if needed. Return null to skip logging the given line. Subclasses may override this method if further processing is required.- Parameters:
s
- an input line as was written to the stream- Returns:
- processed line or null if no logging is required
-
-