to.tetramorph.util
クラス LoggerOutputStream
java.lang.Object
java.io.OutputStream
to.tetramorph.util.LoggerOutputStream
- すべての実装されたインタフェース:
- Closeable, Flushable
public class LoggerOutputStream
- extends OutputStream
System.outやSystem.errの出力を、コンソールだけではなくファイルにも出力できる
ようにするストリーム。
次のように使う。
エラーと標準出力を別々にファイル出力したいとき。
System.setOut(new PrintStream(new LoggerOutputStream( log_file,System.out)));
System.setErr(new PrintStream(new LoggerOutputStream( err_file,System.out)));
エラーと標準出力をまとめて一本のファイルに記録したいとき。
PrintStream ps = new PrintStream(new LoggerOutputStream( log_file,System.out));
System.setOut(ps);
System.setErr(ps);
なおスレッドセーフではない。スレッドセーフであるべきだが、それを実装しようと
するとこういうやり方ではそもそも無理がありすぎる。
クラス java.lang.Object から継承されたメソッド |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LoggerOutputStream
public LoggerOutputStream(File logFile,
PrintStream ps)
throws IOException
- 例外:
IOException
write
public void write(int b)
throws IOException
- 定義:
- クラス
OutputStream
内の write
- 例外:
IOException
close
public void close()
- 定義:
- インタフェース
Closeable
内の close
- オーバーライド:
- クラス
OutputStream
内の close