

Ask YC: Why do so many people always write their own logger? - angstrom

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
======
jhrobert
There 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>

~~~
aristus
Nice -- one of those "wtf...oooooh!" hacks. :)

------
mojuba
One 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.

------
LogicHoleFlaw
This 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.

------
tuukkah
What's a logger in this context?

~~~
angstrom
In 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.

------
yawl
I would understand that, as it 'looks' easy to write a logger, and other
people's logger 'looks' complicated.

