什么是具有字符串操作在其中的调试语句的最佳做法? [英] What is the best practice for debug statements which have string operations in them?

查看:124
本文介绍了什么是具有字符串操作在其中的调试语句的最佳做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常发现自己增加任何concatonated字符串或在log4net的和log4j的,我应该围绕以如果调试块这些调试语句我的调试语句使用字符串格式化从通过处理这些参数,浪费资源管不住自己,即使调试语句将不被打印出来?

I often find myself adding either concatonated strings or using a string formatter in my debug statements in log4net and log4j should I surround these debug statements with an "if debug" block to stop myself from wasting resources by processing these parameters even though the debug statement will not be printed out?

我会假设,检查是否(isDebug)会比具有字符串操作存在的更快和更有效,但它会导致该程序运行不同(快)当调试级别设置调试相比,这可能意味着在生产中发生的同步问题,当我在写日志不会发生高。

I would assume that checking if (isDebug) would be quicker and more efficient than having the string operations occuring, however it would lead to the program operating differently (faster) when the debug level is set higher than debug, which could mean that synchronisation problems that happen in production don't happen when I'm writing to the log.

推荐答案

用于Java,你可以尝试 log5j

for Java you can try log5j.

log4j的:

log.debug("This thing broke: " + foo + " due to bar: " + bar + " on this thing: " + car);



log5j:

log5j:

log.debug("This thing broke: %s due to bar: %s on this thing: %s", foo, bar, car);
log.debug("Exception #%d", aThrowable, exceptionsCount++);

这篇关于什么是具有字符串操作在其中的调试语句的最佳做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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