English 中文(简体)
调控调试代码
原标题:Managing debugging code

在某些项目中,使用 IDE 调试功能变得非常长, 特别是在与图形合作时, 所以有时我使用调试代码, 这样的代码根据环境, 打印出值, 有时在项目本身上, 有时在控制台上。 但是当项目完成后, 很难找到调试代码, 并移除它, 当一个不想要的东西突然出现时, 它显得很奇怪。 我还是一个学生, 以后学习会更好, 如何管理它呢?

搜索时我找不到合适的答案, 但我有几件事想:

  1. 一旦测试模块, 即刻删除代码, 这样就更少了 。 它有效, 但当模块以后( 更高层次) 需要测试时, 它会再次添加上方的代码, 而不是删除的内容, 但仍要添加 。

  2. if 包围它,以确保它只在 debuging 旗为真时才运行,并保留在项目的最终版本中。

  3. 计划项目调试代码,将方法和类别分开(如有可能),并删除电话和物品,以及完成工作时。

管理它的适当方式是什么?

最佳回答

最容易的方式是使用 < code> 调试 旗。

如果您想要/ 不想调试, 您需要重新编译工程 。

更好的办法是让标记使用配置文件/命令行参数的值, 这样您就可以控制调试, 而不必重新编译工程 。

一个更好的办法就是使用一个强大的伐木图书馆(如果有的话),并利用其设施 -- -- 好处是,你可以更好地微调你想记录的内容,在哪里以及以何种格式记录。

问题回答

最好的办法是在代码中调试变量

set isDebugEnabled=true // in case of development server
set isDebugEnabled=false // in case of production server

Or logging can be managed on production also for tracking issue but not upto that extent as its needed on develpment server

var isDebugEnabled=ConfigurationManager.Appsettings["isDebugEnabled"].ToString();
if(Convert.ToBoolean(isDebugEnabled))
{
  Console.log("Log Message");
}

不要忘记检查窗口。 如果 Console.Log 不支持上面的语句, 则此选项会被排除 :

var isDebugEnabled=ConfigurationManager.Appsettings["isDebugEnabled"].ToString();
if(Convert.ToBoolean(isDebugEnabled) && window.Console)
{
  Console.log("Log Message");
}
else
{
  //Follow file logging mechanism.
}




相关问题
XML-RPC Standard and XML Data Type

I was looking at XML-RPC for a project. And correct me if I m wrong, but it seems like XML-RPC has no XML datatype. Are you supposed to pass as a string? or something else? Am I missing something? ...

Is it exists any "rss hosting" with API for creating feeds

I am creating a desktop app that will create some reports. I want to export these reports as RSS or ATOM feeds. I can easily create feeds with Rome lib for Java. But I have no idea how to spread them. ...

Improving Q-Learning

I am currently using Q-Learning to try to teach a bot how to move in a room filled with walls/obstacles. It must start in any place in the room and get to the goal state(this might be, to the tile ...

High-traffic, Highly-secure web API, what language? [closed]

If you were planning on building a high-traffic, very secure site what language would you use? For example, if you were planning on say building an authorize.net-scale site, that had to handle tons ...

Def, Void, Function?

Recently, I ve been learning different programming langages, and come across many different names to initalize a function construct. For instance, ruby and python use the def keyword, and php and ...

热门标签