Java: Using printStackTrace in a production environment

I am going to deploy our web application to the Production server. Does printStackTrace include a catch block in production? (because the logs under the catch block do not help to find out the exact cause of the error) So please tell me, is it possible to have printStackTrace under the catch block?

For example, I purposefully set the wrong port number, and printStackTrace () gives me this information.

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)

Magazine style:

And where, how does the logging give this (I use the Apache community logging mechanism for 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

So, please tell me, is it permissible to have printStackTrace under the catch block?

+4
source share
4 answers

stacktrace, . :

log.error(Object message, Throwable t);

Log.write("**EXCEPTION INSIDE execute " + e, Log.INFO); , String, toString() e- "**EXCEPTION INSIDE execute " String, , .

http://commons.apache.org/logging/guide.html#Logging a

+6

stacktrace , , .

printStackTrace , ( , java).

, . , , (, ).

, .

+1

, , , , , . , , log4j commons logger, ( , ..), stacktrace, , .

In addition, having a container / web server log with traces often raises doubts about clients, and having a structured application log makes them more relaxed. The question of perception.

0
source

Yes, it is permissible to print stack traces for exceptions in production environments. You can still throw an exception to handle if you want.

0
source

All Articles