Click here to register.
      

Low-hanging Fruit

Design Squid
frodwith
Low-hanging Fruit
frodwith · 6/30/2009 10:21 am

I've recently been working on a long-running daemon process that logs all of its debug output, errors, etc. to a single file via Log::Log4perl.  Log4perl is a great logging system and extremely flexible.  We use it for all our logging in WebGUI.  One of the things it is missing, though, is an easy way to capture output from a filehandle and log it.  This is a rather minor thing, as if you have control of the code that is printing to said filehandle, you can simply change the 'print STDERR' or 'warn' to a '$log->warn()'.  If you don't have control of the code, however...


This is addressed by an entry in Log4perl's FAQ.  It says, in essence, "Tie the offending filehandle to a class that logs the error.  Here's an example, but it will completely explode if you send your logging output to the same filehandle."  What should have happened is this:

  1. FAQ author starts typing up example code, then realizes this will be written a million times for no good reason, and releases a CPAN module.
  2. Someone needs to log to the same filehandle they're tying, so they submit a patch to the author.
  3. The author reviews the patch and applies it, releasing the updated module on CPAN.
  4. No one ever asks this question again.

If this had actually happened, I wouldn't be writing this blog entry.  Instead, they left a full, half-functional class just sitting there in the FAQ.  Why?  It took me about half an hour to write simple documentation, package the module as a cpan distribution, set up a github repo, and upload Tie::Log4perl to CPAN.  I never have to write this code again, and neither does anyone else.  On top of that, it doesn't have the bug that the FAQ example has, and it won't for anyone else, ever.  I can't see how this is anything but a win.


So my question is, why don't more authors release simple, uncontroversial, but useful code like this on CPAN?  Who cares if the code is only 30 lines long including documentation?  It's useful, it cuts down on code duplication, and now people can submit patches or fork my github repo.  So even if I did something wrong, now it's public code that other people can fix for me.  Next time you solve a simple problem that you can see yourself or someone else needing to solve in the future, release it on CPAN.  If you don't know how to package up a CPAN distribution, look at examples and read a couple of tutorials online.  It's very easy, and it feels good too.

·
Stick
Lock
Subscribe