记录错误的最佳做法是什么? [英] What are the best practices to log an error?

查看:110
本文介绍了记录错误的最佳做法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  System.out.println(method aMethod with parameters a: + a +b:+ b); 
print(第88行错误);

so ..记录错误的最佳做法是什么?



编辑:



这是java,但可以是C / C ++,基本等。 b $ b

解决方案

Apache Commons Logging不适用于应用程序通用日志记录。它旨在被不想强制对API用户进行日志记录实现的库或API使用。



Commons Logging还存在类加载问题。 p>

选择[许多]日志记录api中的一个,最广泛使用的可能是 log4j Java Logging API



如果要实现独立性,您可能需要考虑 SLF4J ,由原始作者log4j。



选择了一个实现,然后使用记录级别/严格程度一致,以便搜索/过滤日志更容易。


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");

so.. What are the best practices to log an error?

EDIT:

This is java but could be C/C++, basic, etc.

解决方案

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.

这篇关于记录错误的最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆