What are the best practices to log an error?

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

    Apache Commons Logging is not intended for applications general logging. It's intended to be used by libraries or APIs that don't want to force a logging implementation on the API's user.

    There are also classloading issues with Commons Logging.

    Pick one of the [many] logging api's, the most widely used probably being log4j or the Java Logging API.

    If you want implementation independence, you might want to consider SLF4J, by the original author of log4j.

    Having picked an implementation, then use the logging levels/severity within that implementation consistently, so that searching/filtering logs is easier.

提交回复
热议问题