Why Errors Are Your Best Friend

Logging  PHP 

As developers, we can believe errors are negative reflections on our applications. But are they really so? In today’s post, I show you how they’re anything but negative, they’re actually very very positive, when interpreted correctly.


Synopsis

Sometimes, as developers, we believe errors are negative reflections on our applications. But are they really so? In today’s post, I show you how they’re anything but negative, they’re actually very very positive, when interpreted correctly.

Why is this so?

They can be a source of never ending knowledge about your application, helping you, guiding you on the way to forever making it better. They can tell you so much about your application, such as:

  • How people are using the site (which you didn’t allow for)
  • What different crawlers are expecting
  • Odd and curious requests that people are making of it
  • Potentially what people would like or expect to see

Above and beyond this, they’re also a way to grow your development education - as you’ll see.

A Simple Example

In an application that I’ve written, based on Zend Framework 1, I have a pretty fair amount of logging going on, using Zend Log. To save me having to always check it, I configured an email writer that let’s me know about different event priorities via email. Below is a sample of a recent one (formatted for readability):

2012-12-03T03:52:30-08:00 CRIT (2): Error: Application error.
Reason: exception ‘Zend_Acl_Exception’ with message
‘Resource ‘default:humans.txt’ not found’ in
/srv/www/library/Zend/Acl.php:365

As you can see, something has requested humans.txt, which the application doesn’t support. At first, I was a bit bemused when I read this and wondered why anyone would request such a file, until I did a bit of googling on the subject and came across this site that explains what they are.

It turns out, a humans.txt file is:

…an initiative for knowing the people behind a website. It’s a TXT file that contains information about the different people who have contributed to building the website.

As I read more of the site I became increasingly intrigued and actually rather hooked. Though I don’t really need it, it seemed like a good idea to add one. Ok, I am, like a lot of us geeks, a little bit of a fanboy of all things new and shiny at heart. Plus, it should take no more than a few minutes to create and doesn’t detract from the site as a whole.

So here’s what I came up with. Short, sweet and straight to the point:

/* TEAM */
    Chef: Matthew Setter
    Contact: matthew [at] maltblue.com
    Twitter: @settermjd
    From:Brisbane, Australia

    UI developer: Scott McKenzie
    Twitter: @zerohourandco
    From:Brisbane, Australia

/* THANKS */

    Inspiration: Jon Lebensold
    Contact: john [at] lebensold.net

    Inspiration: Ryan Bates
    Twitter: @rbates

    Hosting: cloudControl
    Contact: hp [at] cloudcontrol.com

/* SITE */
    Language:English
    Doctype:HTML5
    IDE: Sublime Text

I’ve said that I’m the man behind the site, given a plug to the awesome design company that made the UI and some special thanks to the people that inspired and host the site, with a little bit of information about it.

Winding Up

Without having seen this log message, I never would have even heard of humans.txt let alone known what it was. Thanks to the error message, I’ve been given a window in to another aspect of modern website design, increased my knowledge, even if only slightly, but overall, learned something new.

If you’re thinking logs aren’t all that helpful - I say you’re wrong. Have a look over the error logs of your application. What gems of information are contained in there. I’m sure that you’ll have ones a lot more intense than this simple example.

To paraphrase the Welsh poet, Dylan Thomas, do not let thy logs go gentle into that good night. Read them, analyse them and use the information that they provide to make your site or application better than before.

Share what your logs say in the comments - I’m intrigued to hear.

image copyright hamilton.lima


You might also be interested in these tutorials too...

Painless Data Traversal with PHP FilterIterators
Thu, Oct 25, 2012

Painless Data Traversal with PHP FilterIterators

There are a lot of ways to traverse data in PHP, including while, do while, for and foreach loops. These are fine in a lot of cases. But what if you want to reuse looping logic or have somewhat complex logic? Enter the FilterIterator.

Mon, Oct 22, 2012

Make Freelance Business Administration Easy - Use FreeAgent

Whether you’re a casual freelance php developer or running a professional freelance business, you’ll know just how much work can be involved. Not only do you have applications to design, develop and support. But you’ve also got business functions such as marketing, advertising, finances and networking as well. In this post we show you a tool to massively reduce your workload - FreeAgent.


Want more tutorials like this?

If so, enter your email address in the field below and click subscribe.

You can unsubscribe at any time by clicking the link in the footer of the emails you'll receive. Here's my privacy policy, if you'd like to know more. I use Mailchimp to send emails. You can learn more about their privacy practices here.

Join the discussion

comments powered by Disqus