Package com.atlassian.confluence.logging
Class LoggingOutputStream
java.lang.Object
java.io.OutputStream
com.atlassian.confluence.logging.LoggingOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
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
ConstructorDescriptionLoggingOutputStream
(@NonNull org.apache.log4j.Logger log, @NonNull org.apache.log4j.Level level) Creates the Logging instance to flush to the given logger. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
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 Details
-
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 Details
-
write
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
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
-