jboss是如何实现将system.out.println打印的内容写入server.log中的
modules/system/layers/base/org/jboss/stdio/main/jboss-stdio-1.0.2.GA.jar
public class TestStream extends FileOutputStream{
OutputStream out;
public TestStream(String name, OutputStream out) throws FileNotFoundException {
super(name);
this.out = out;
}
@Override
public void write(byte[] b,int off,int len) throws IOException {
super.write(b,off,len);
out.write(b, off, len);
}
}
public static void main(String[] args){
PrintStream out = System.out;
try (FileOutputStream fis = new TestStream("d://test.txt",out)) {
System.setOut(new PrintStream(fis));
System.out.println("asdf测试");
} catch (IOException e) {
throw new RuntimeException(e);
}
}