What are the best practices to log an error?

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

    Some suggested best-practices

    • Use a logging framework. This will allow you to:

      • Easily change the destination of your log messages
      • Filter log messages based on severity
      • Support internationalised log messages
    • If you are using java, then slf4j is now preferred to Jakarta commons logging as the logging facade.

    • As stated slf4j is a facade, and you have to then pick an underlying implementation. Either log4j, java.util.logging, or 'simple'.

    • Follow your framework's advice to ensuring expensive logging operations are not needlessly carried out

提交回复
热议问题