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
ConstructorsConstructorDescriptionLoggingOutputStream(@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 TypeMethodDescriptionvoidclose()Closes this output stream and releases any system resources associated with this stream.voidflush()Flushes this output stream and forces any buffered output bytes to be written out.protected StringExamines an inout line and amends, if needed.voidwrite(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:
writein 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:
flushin interfaceFlushable- Overrides:
flushin classOutputStream
-
close
public void close()Closes this output stream and releases any system resources associated with this stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein 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
-