一种解决方案是将OutputStream. 您只需执行write( int b ). 然后在构造函数PrintStream中用你的创建一个OutputStream。
它可能看起来像:
public class L4JOS extends OutputStream {
logger = Logger.getLogger( "std.out" );
private int lineEnd = (int)'\n';
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
public void write( int b ) throws IOException {
baos.write( b );
if ( b == lineEnd ) {
logger.info( baos.toString() );
baos.reset();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果它是多线程的,那么你有更多的工作。并确保 appender 没有转到 System.out。