log4j.properties
log4j.rootLogger=ERROR,R
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=D:/backup.log
log4j.appender.R.DatePattern = '. 'yyyy-MM-dd
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n
在日志文件里面有输出:
2007-09-03 21:16:26 [com.TrackAction]-[ERROR] java.net.ConnectException: Connection timed out: connect
而在控制台里面则有输出:
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:364)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at java.net.Socket. <init> (Socket.java:365)
at java.net.Socket. <init> (Socket.java:178)
at com.kj133.action.TrackAction.init(TrackAction.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
我怎么才能把详细信息输出到日志文件里面?
------解决方法--------------------------------------------------------
log.error( "输入你要描述的信息 ",e);
这样即可得到堆栈信息,不要使用log.error(e)和log.error(e.getStac*****)
------解决方法--------------------------------------------------------
log.error( "输入你要描述的信息 ",e);要将异常对象作为第二个参数传递到log的方法中