3 ms·
Ask YC: Why do so many people always write their own logger?
I've seen applications where every major project had a logger written by the person who wrote the project, rather than at the very least a common logger. But what really bugs me is the people who bother writing one anyways and it does nothing novel to justify its use over some LGPL/BSD/MIT licensed library. //end rant
- tuukkah 19y agoWhat's a logger in this context?
- angstrom 19y agoIn this context they're mostly log file generators and one for outputting system log messages. Still, there is no reason I have ever seen for having more than one or wasting time rolling your own unless you need platform independence.
- mojuba 19y agoOne reason is portability, especially for applications running on both UNIX and Windows. The Windows system event logger is so awful I sometimes think it was made for robots rather than human programmers. It's just useless. Why not UNIX syslog? It's a powerful, universal logging tool, optimized for performance, and it can take care of concurrency, repeating message "storms", automatic archiving, etc. It can also store messages pertaining to a particular subsystem in a separate file, and that's what most developers want. The problem is that system configuration must be changed for that (presumably when installing your application) and this is not portable across all UNIX systems, AFAIK. Why not some widely available libraries then, like you said? Most of them are overcomplicated, don't support concurrency or lack some other very basic, simple features you might need in your project. So, there's always a temptation to write a custom logger because it looks simple in the beginning - just take the string and write it to a file, right? And it is, in fact, not at all simple if you think of concurrency and performance. I usually take UNIX syslog as a basis and I write my own syslog emulator on Windows whenever I need to maintain portability of the source.
- yawl 19y agoI would understand that, as it 'looks' easy to write a logger, and other people's logger 'looks' complicated.
- LogicHoleFlaw 19y agoThis bugs me too. At my current workplace the justification was that it was simpler, and therefore faster. I'm not sure I buy it though. It's still inefficient in multiple ways and not nearly as flexible as one of the loggers based on the popular log4j style. My own personal preference is to use something which shoves your logging out to syslog. Then you get some pretty fine-grained control over what your logging is doing, and it's easy to say, do all of your logging across the network. Unfortunately, taking advantage of the UNIX concept of many small tools working together hasn't really taken root in many programmers' design approaches.
- jhrobert 19y agoThere is a lot of confusion around logging because software developers use it to debug code whereas IT people use it to manage alarms in systems. Call me an idiot but I did write custom loggers multiple times in the past. I did that because I use a lot of trace messages for debugging and that is so unusual that it kills the existing loggers big way. Nowadays I don't do that anymore, I use the system logger. I do that because I managed to find a way to factorize the logging logic out from the filtering logic. For example in JavaScript I do var de = isEnabledTraceXXXXX(); xxx de&&bug( "Tracing YYYY"); This is ultra efficient and readable thanks to the && progressive operator. For those interested, I described that trick there: http://virteal.com/DebugDarling http://virteal.com/DebugDarling