Logging practices?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Logging practices?

OmegaKV
Whenever I want to debug something, I use print statements and then delete them when I am done, because otherwise too much information is printed to the terminal. But then at some point in the future, I might want the same print statement to debug something else, so I end up rewriting the same print statement, only to delete it again.

Is there any way around this problem, so that I do not have to keep rewriting print statements? I think log levels are an attempt to address this problem, but I never found them to be of any use, because the "DEBUG" log level very quickly becomes so verbose that it becomes useless.

One idea I had as I was writing this is to give each log statement an identifier (e.g. "log(int identifier, string statement)"), and then at runtime you can select which log statement is enabled by writing to a variable or perhaps a list, specifying the identifier(s) of the log statements you want printed.
Reply | Threaded
Open this post in threaded view
|

Re: Logging practices?

fschmidt
Administrator
If I think some logging for debugging may be useful in the future, I comment it out instead of deleting it.  When I don't think it will be useful anymore, then I delete it.
Reply | Threaded
Open this post in threaded view
|

Re: Logging practices?

OmegaKV
That is basically what I do, but for things that are cumbersome to recompile/restart, it would be nice to have some flexibility at runtime over what you log. Imagine someone complains about a bug in some feature in your software, and then you go into a GUI interface, and and enter an identifier to enable logging of the loop you suspect the bug being in. That would be kind of cool.