Zend_Log wrapper

This is a small class to wrap a zend log, so we dont have to call the registry and the logger to log a message.

With this, instead of :

$logger = Zend_Registry::get('log');
$logger->info($message);

we can do:

ZC_FileLogger::info($message);

The full class:

<?php
class ZC_FileLogger
{
    /**
     *
     * @var Zend_Log
     */
    protected $logger;

    /**
     *
     * @var ZC_FileLogger
     */
    static $fileLogger = null;

    public static function getInstance()
    {
        if (self::$fileLogger === null)
        {
            self::$fileLogger = new self();
        }
        return self::$fileLogger;
    }
    /**
     *
     * @return Zend_Log
     */
    public function getLog()
    {
        return $this->logger;
    }

    protected function __construct()
    {
        $this->logger = Zend_Registry::get('log');
    }
    /**
     * log a message
     * @param string $message
     */
    public static function info($message)
    {
        self::getInstance()->getLog()->info($message);
    }
}

Credits: Jon Lebensold

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s