What are the best practices to log an error?

后端 未结 8 878
野的像风
野的像风 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:18

    Aside from technical considerations from other answers it is advisable to log a meaningful message and perhaps some steps to avoid the error in the future. Depending on the errors, of course.

    You could get more out of a I/O-Error when the message states something like "Could not read from file X, you don't have the appropriate permission."

    See more examples on SO or search the web.

提交回复
热议问题