我将要在生产服务器上部署我们的Web应用程序。 在生产环境下,是否可以在catch块中包含printStackTrace?(因为在catch块下的日志无法帮助我们知道错误的确切原因) 请告诉我,在catch块下使用printStackTrace是否可接受?
例如,我故意放置了一个无效的端口号,并且printStackTrace()会给我提供这些信息。
printStackTrace() :
java.lang.IllegalArgumentException: port out of range:80800
at java.net.InetSocketAddress.<init>(InetSocketAddress.java:118)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:395)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:234)
at sun.net.www.http.HttpClient.New(HttpClient.java:307)
at sun.net.www.http.HttpClient.New(HttpClient.java:324)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:970)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:911)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:836)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1014)
at com.tata.util.XmlClient.execute(HttpXmlClient.java:83)
日志样式:
而当使用 Apache Commons Logging 机制进行日志记录时,日志会像这样显示:
Log.write("**EXCEPTION INSIDE execute " + e, Log.INFO);
06/Jan/2012 16:25:55 - main:http-8080-2 <> <60990020>**EXCEPTION INSIDE execute java.lang.IllegalArgumentException: port out of range:80800
请问在catch块中使用printStackTrace是否可行?