What are the best practices to log an error?

后端 未结 8 830
野的像风
野的像风 2020-12-29 07:47

Many times I saw logging of errors like these:

System.out.println(\"Method aMethod with parameters a:\"+a+\" b: \"+b);
print(\"Error in line 88\");
         


        
8条回答
  •  情话喂你
    2020-12-29 08:34

    The apache common logging API as mentioned above is a great resource. Referring back to java, there is also a standard error output stream (System.err).

    Directly from the Java API:

    This stream is already open and ready to accept output data.

    Typically this stream corresponds to display output or another output destination specified by the host environment or user. By convention, this output stream is used to display error messages or other information that should come to the immediate attention of a user even if the principal output stream, the value of the variable out, has been redirected to a file or other destination that is typically not continuously monitored.

提交回复
热议问题