Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I use xlog().

My xlog() has the form xlog(<filter>,<format string>, <arguments ...>)

Instead of printing every time, the filter only allows printing in certain circumstances, 16 different sets of circumstances. The format string and argument list, are just the same as the printf() format string and argument list.

The other difference is that the output of xlog() goes to a log-file, not the screen. This allows long and careful inspection of the output, as well as allowing use of grep and other utilities to aid in the quest for bugs.

Think of it as a super-duper printf(). <grin>



I do that exact same thing but the filter is just verbosity level. I end up using my printf-wrapper-with-verbosity-filter for essentially all output, and it serves as a global verbosity knob that goes down as well as up. Default verbose level is 1, and setting to 0 makes the app silent.

Small problem though is a lot of times a nice informative message is constructed of stuff that takes work to do, and the work has to be done and then handed to my dbg(v,fmt,args...), only to be thrown away in the first line of dbg() if(verbose<v) So I have chunks of code behind if(verbose>3) and then dbg(3,...) inside there which just bugs me aesthetically :)

I don't want to think about trying to make something that somehow takes an argument for what work to do instead of a simple value the result of the work. Function pointer? It would be less ergonomic than just if(verbose>4)




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: