当前位置: 代码迷 >> WebSphere >> websphere日志的有关问题
  详细解决方案

websphere日志的有关问题

热度:6850   发布时间:2013-02-26 00:00:00.0
websphere日志的问题
websphere日志的问题 中的systemout.log 记录的是打印到屏幕上的信息。

我自己项目中的system。out。println 能不能不显示在这个文件中,只放websphere自己的

------解决方案--------------------------------------------------------
好像不行,何不log4j到自己的日志里?
------解决方案--------------------------------------------------------
将控制台输出(System.out.println)重定向到文件里面,就可以了呀!



PrintStream printStream = null;
PrintStream sysout = System.out;
PrintStream syserr = System.err;
try {
File file = new File("c:\\systemout.log");

if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
printStream = new PrintStream(new FileOutputStream(new File(
"c:\\systemout.log"), true));
System.setOut(printStream);
System.setErr(printStream);
System.out.println("System.out.println");
System.err.println("System.err.println");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (printStream != null) {
printStream.close();
}
}