<?php
/**
* SVF_Log
*
* LICENSE
*
* This source file is subject to the BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://svf.webutilities.ch/license/bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to hide@address.com so we can send you a copy immediately.
*
* @package SVF
* @category Log
* @uses Zend_Log
* @uses Zend_Log_Writer_Firebug
* @uses Zend_Log_Writer_Stream
* @copyright Copyright (c) 2002-2008 Webutilities CH Inc. (http://www.webutilities.ch)
* @license BSD {@link http://svf.webutilities.ch/license/bsd}
* @author Silvan von Felten
* @version $Id$
*/
require_once 'Zend/Log.php';
class SVF_Log extends Zend_Log {
/**
* Instance
*
* @var Zend_Log_Writer_Firebug
*/
protected $_writerFirebug;
/**
* Instance
*
* @var Zend_Log_Writer_Stream
*/
protected $_writerPhp;
/**
* Instance
*
* @var Zend_Log_Writer_Stream
*/
protected $_writerFile;
/**
* Filter
*
* Set the filter of the logger.
*
* @param string $priority
* @return SVF_Log
*
*/
public function filter($priority = null) {
require_once 'Zend/Log/Filter/Priority.php';
$filter = new Zend_Log_Filter_Priority ( $priority );
$this->addFilter ( $filter );
return $this;
}
/**
* SetEventItems
*
* Set the events to the logger
*
* @param array $events
* @return SVF_Log
*
*/
public function setEventItems($events) {
foreach ( $events as $key => $val ) {
$this->setEventItem ( $key, $val );
}
return $this;
}
/**
* SetWriterFormatterXml
*
* @param Zend_Log_Writer_Abstract $writer
* @param XML_String $root
* @param XML_String $elements
* @return SVF_Log
*
*/
public function setWriterFormatterXml(Zend_Log_Writer_Abstract $writer,
$root = null, $elements = null) {
require_once 'Zend/Log/Formatter/Xml.php';
$formatter = new Zend_Log_Formatter_Xml ( $root, $elements );
$writer->setFormatter ( $formatter );
return $this;
}
/**
* setWriterFormatterXmls
*
* @param Zend_Log_Writer_Abstract array $writer
* @param XML_String $root
* @param XML_String $elements
* @return SVF_Log
*
*/
public function setWriterFormatterXmls($writers, $root = null,
$elements = null) {
foreach ( $writers as $writer ) {
$this->setWriterFormatterXml ( $writer, $root, $elements );
}
return $this;
}
/**
* SetWriterFormatterSimple
*
* @param Zend_Log_Writer_Abstract $writer
* @param string $format
* @return SVF_Log
*
*/
public function setWriterFormatterSimple(Zend_Log_Writer_Abstract $writer,
$format) {
if (null !== $format) {
require_once 'Zend/Log/Formatter/Simple.php';
$formatter = new Zend_Log_Formatter_Simple ( $format );
$writer->setFormatter ( $formatter );
}
return $this;
}
/**
* SetWriterFormatterSimples
*
* @param Zend_Log_Writer_Abstract array $writers
* @param string $format
* @return SVF_Log
*
*/
public function setWriterFormatterSimples($writers, $format) {
foreach ( $writers as $writer ) {
$this->setWriterFormatterSimple ( $writer, $format );
}
return $this;
}
/**
* AddPrioritys
*
* Add prioritys to the logger.
*
* @param array $priorities
* @return SVF_Log
*
*/
public function addPrioritys($priorities = array()) {
foreach ( $priorities as $key => $val ) {
$this->addPriority ( strtoupper ( $key ), $val );
}
return $this;
}
/**
* AddFirebug
*
* Add firebug writer to the logger.
* Set the filter of the writer.
*
* @param string $filter
* @return SVF_Log
*
*/
public function addFirebug($filter = null) {
$this->addWriterFirebug ();
if (null !== $filter) {
$this->_writerFirebug->addfilter ( $filter );
}
return $this;
}
/**
* AddPhp
*
* Add php writer to the logger.
* Set the filter of the writer.
*
* @param string $filter
* @return SVF_Log
*
*/
public function addPhp($filter = null) {
$this->addWriterPhp ();
if (null !== $filter) {
$this->_writerPhp->addfilter ( $filter );
}
return $this;
}
/**
* AddFile
*
* Add file writer to the logger.
* Set the filter of the writer.
*
* @param string $file
* @param string $filter
* @param string $mode
* @return SVF_Log
*
*/
public function addFile($file = './log/access.log',
$filter = null, $mode = 'a') {
$this->addWriterFile ( $file, $mode );
if (null !== $filter) {
$this->_writerFile [$file]->addfilter ( $filter );
}
return $this;
}
/**
* AddWriterFirebug
*
* Get new instance from Zend_Log_Writer_Firebug class.
* Add the instance to the protected var $_writerFirebug.
*
* @return Zend_Log_Writer_Firebug
*
*/
public function addWriterFirebug() {
if (null === $this->_writerFirebug) {
require_once 'Zend/Log/Writer/Firebug.php';
$this->_writerFirebug = new Zend_Log_Writer_Firebug ( );
$this->addWriter ( $this->_writerFirebug );
}
return $this->_writerFirebug;
}
/**
* AddWriterPhp
*
* Get new instance from Zend_Log_Writer_Stream class with php output.
* Add the instance to the protected var $_writerPhp.
*
* @return Zend_Log_Writer_Stream
*
*/
public function addWriterPhp() {
if (null === $this->_writerPhp) {
require_once 'Zend/Log/Writer/Stream.php';
$this->_writerPhp = new Zend_Log_Writer_Stream ( 'php://output' );
$this->addWriter ( $this->_writerPhp );
}
return $this->_writerPhp;
}
/**
* AddWriterFile
*
* Get new instance from Zend_Log_Writer_Stream class with file path.
* Add the instance to the protected variable $_writerFile array,
* to support more then just one logger file.
* Set the key with the specified path to have hash support.
*
* @param string $file
* @param string $mode
* @return Zend_Log_Writer_Stream
*
*/
public function addWriterFile($file, $mode = 'a') {
if (empty ( $this->_writerFile [$file] )) {
require_once 'Zend/Log/Writer/Stream.php';
$this->_writerFile [$file] = new Zend_Log_Writer_Stream ( $file, $mode );
$this->addWriter ( $this->_writerFile [$file] );
}
return $this->_writerFile [$file];
}
/**
* GetWriterFirebug
*
* Get Zend_Log_Writer_Firebug class instance.
*
* @return Zend_Log_Writer_Firebug
*
*/
public function getWriterFirebug() {
if (empty ( $this->_writerFirebug )) {
$this->addWriterFirebug ();
}
return $this->_writerFirebug;
}
/**
* GetWriterPhp
*
* Get Zend_Log_Writer_Stream class instance.
*
* @return Zend_Log_Writer_Stream
*
*/
public function getWriterPhp() {
if (empty ( $this->_writerPhp )) {
$this->addWriterPhp ();
}
return $this->_writerPhp;
}
/**
* GetWriterFile
*
* Get Zend_Log_Writer_Stream class instance specyfied by the file.
*
* @param string $file
* @return Zend_Log_Writer_Stream
*
*/
public function getWriterFile($file) {
if (empty ( $this->_writerFile [$file] )) {
$this->addWriterFile ( $file );
}
return $this->_writerFile [$file];
}
/**
* GetWriterFiles
*
* Get all Zend_Log_Writer_Stream class instances.
*
* @return array Zend_Log_Writer_Stream
*
*/
public function getWriterFiles() {
return $this->_writerFile;
}
}