alistairphillips.com

I’m : a web and mobile developer based in the Australia.


Zend_Log and custom writer Log_Writer_Prowl

Prowl is an iPhone app that's usually used to extend Growl notifications from your Mac to the iPhone. By using the Prowl API you can extend the application to almost anything you like. So following in the footsteps of Log_Writer_Script here's Log_Writer_Prowl in use:

<?php
    date_default_timezone_set('Europe/London');
    require_once('Zend/Log.php');
    require_once('Log_Writer_Prowl.php');

    $params = array(
        'apikey'      => 'my_api_key',
        'application' => 'my_application_name'
    );

    $writer = new Log_Writer_Prowl( $params );
    $logger = new Zend_Log( $writer );
    $logger->log( 'Example of Zend_Log::DEBUG', Zend_Log::DEBUG );
?>

Error levels have been re-written as below and I'll include an option later on allowing you to re-map these:

<?php
    // We'll need to re-write the event priority
    switch( $event['priority'] ) {
        case 0: // Emergency
        case 1: // Alert
            $event['priority'] = 2; // Prowl Emergency
            break;
        case 2: // Critical
            $event['priority'] = 1; // Prowl High
            break;
        case 3: // Error
            $event['priority'] = 0; // Prowl Normal
            break;
        case 4: // Warn
            $event['priority'] = -1; // Prowl Moderate
            break;
        case 5: // Notice
        case 6: // Info
        case 7: // Debug
            $event['priority'] = -2; // Prowl Very Low
            break;
    }
?>

Here's the source if you'd like /php/zend/log/prowl/Log_Writer_Prowl.phps