Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep your own debug lines without checking them in?

When working on some code, I add extra debug logging of some kind to make it easier for me to trace the state and values that I care about for this particular fix.

But if I would check this in into the source code repository, my colleagues would get angry on me for polluting the Log output and polluting the code.

So how do I locally keep these lines of code that are important to me, without checking them in?

Clarification: Many answers related to the log output, and that you with log levels can filter that out. And I agree with that.

But. I also mentioned the problem of polluting the actual code. If someone puts a log statement between every other line of code, to print the value of all variables all the time. It really makes the code hard to read. So I would really like to avoid that as well. Basically by not checking in the logging code at all. So the question is: how to keep your own special purpose log lines. So you can use them for your debug builds, without cluttering up the checked in code.

like image 664
Andreas Avatar asked Oct 16 '08 15:10

Andreas


2 Answers

If the only objetive of the debugging code you are having problems with is to trace the values of some varibles I think that what you really need is a debugger. With a debugger you can watch the state of any variable in any moment.

If you cannot use a debugger, then you can add some code to print the values in some debug output. But this code should be only a few lines whose objective has to be to make easier the fix you are doing. Once it's commited to trunk it's fixed and then you shouldn't need more those debug lines, so you must delete them. Not delete all the debug code, good debug code is very useful, delete only your "personal" tracing debug code.

If the fix is so long that you want to save your progress commiting to the repository, then what you need is a branch, in this branch you can add so much debugging code as you want, but anyway you should remove it when merging in trunk.

like image 173
Jaime Soriano Avatar answered Sep 28 '22 07:09

Jaime Soriano


But if I would check this in into the source code repository, my colleagues would get angry on me for polluting the Log output and polluting the code.

I'm hoping that your Log framework has a concept of log levels, so that your debugging could easily be turned off. Personally I can't see why people would get angry at more debug logging - because they can just turn it off!

like image 41
matt b Avatar answered Sep 28 '22 09:09

matt b