PEAR Log loggt alles 3x

redX

Erfahrenes Mitglied
Hallo...

Ich möchte ein eigenes Error Handling aufziehen. Ich dachte mir daszu eignet sich das Logging von PEAR ganz gut.

So sieht mal meine Klasse aus:
PHP:
class Arena_Logger {
	/**
	 * PHP logger
	 *
	 * This Logger is used by PHP to log.
	 *
	 * @var Log_composite
	 */
	private $logger;
	
	/**
	 * Overrides the PHP error hanlder.
	 */
	public static function setErrorHandler() {
		//logger which prints to the display.
		$phpConf = array('error_prepend' => '<font color="#ff0000" size="2pt"><tt>[PHP Error]','error_append'  => '</tt></font>');
		$phpDisplay = &Log::singleton('display', '', 'PHP',$phpConf,DISPLAY_LOG_LEVEL);
		
		//logger which prints to a file
		$phpDile = &Log::singleton('file', LOG_FILE, 'PHP Error',array(), FILE_LOG_LEVEL);
		
		//set up logger composite
		$phpLogger = &Log::singleton('composite');
		$phpLogger->addChild($phpDisplay);
		$phpLogger->addChild($phpFile);
		
		//Override the PHP error handler with our own one.
		$errorclass = new Error_Hanlder($phpLogger); 
		$old_error_handler = set_error_handler(array(&$errorclass, 'errorLogger'));
	}
	
	public function __construct($fileName = NULL) {
		//logger which prints to the display.
		$conf = array('error_prepend' => '<font color="#ff0000" size="2pt"><tt>[' . $fileName . ']','error_append'  => '</tt></font>');
		$display = &Log::singleton('display', '', WORK_DIR . $fileName,$conf,DISPLAY_LOG_LEVEL);
		
		//logger which prints to a file
		$file = &Log::singleton('file', LOG_FILE, WORK_DIR . $fileName,array(), FILE_LOG_LEVEL);
		
		//set up logger composite
		$this->logger = &Log::singleton('composite');
		$this->logger->addChild($display);
		$this->logger->addChild($file);
	}
// noch mehr code.
setErrorHandler() ist dazu da, das auch PHP mein logger verwendet. Das funktioniert ja auch.

Jetzt möchte ich in jeder Klasse einen Logger verwenden. Bis jetzt 2 Klassen. Jetzt wenn ein Fehler auftritt, dann loggt jeder Logger. Also der von PHP und die beiden der Klassen. Deshalb wird alles 3x ausgegeben. Ich weiss jedoch nicht was man dagegen unternehmen kann....

PHP:
class main {
	/**
	 * bla bla bla
	 */	
	public function __construct() {
		//bla bla bla
		$this->logger = new Arena_Logger("index.php"); //neuer logger... erster logger
		Arena_Logger::setErrorHandler(); //php logger setzen... zweiter logger
PHP:
class Event_Controller {
	/**
	 * bla bla bla
	 */
	public function __construct($params = "") {
		$this->params = $params;
		$this->logger = new Arena_Logger("event_controller.php"); //dritter logger...
	}
	//bla bla bla
	include("hahahaha.php"); //hahahaha.php gibts nicht. provozierter fehler.
	$this->logger->crit("test"); //Test log...

Ausgabe:
HTML:
<font color="#ff0000" size="2pt"><tt>[index.php]<b>Warning</b>: Event_Controller::include(hahahaha.php) [&lt;a href='function.include'&gt;function.include&lt;/a&gt;]: failed to open stream: No such file or directory in /www/htdocs/v027867/arena/event_controller.php at line 59</tt></font><br />
<font color="#ff0000" size="2pt"><tt>[PHP Error]<b>Warning</b>: Event_Controller::include(hahahaha.php) [&lt;a href='function.include'&gt;function.include&lt;/a&gt;]: failed to open stream: No such file or directory in /www/htdocs/v027867/arena/event_controller.php at line 59</tt></font><br />
<font color="#ff0000" size="2pt"><tt>[event_controller.php]<b>Warning</b>: Event_Controller::include(hahahaha.php) [&lt;a href='function.include'&gt;function.include&lt;/a&gt;]: failed to open stream: No such file or directory in /www/htdocs/v027867/arena/event_controller.php at line 59</tt></font><br />
<font color="#ff0000" size="2pt"><tt>[index.php]<b>Warning</b>: Event_Controller::include(hahahaha.php) [&lt;a href='function.include'&gt;function.include&lt;/a&gt;]: failed to open stream: No such file or directory in /www/htdocs/v027867/arena/event_controller.php at line 59</tt></font><br />
<font color="#ff0000" size="2pt"><tt>[PHP Error]<b>Warning</b>: Event_Controller::include(hahahaha.php) [&lt;a href='function.include'&gt;function.include&lt;/a&gt;]: failed to open stream: No such file or directory in /www/htdocs/v027867/arena/event_controller.php at line 59</tt></font><br />
<font color="#ff0000" size="2pt"><tt>[event_controller.php]<b>Warning</b>: Event_Controller::include(hahahaha.php) [&lt;a href='function.include'&gt;function.include&lt;/a&gt;]: failed to open stream: No such file or directory in /www/htdocs/v027867/arena/event_controller.php at line 59</tt></font><br />
<font color="#ff0000" size="2pt"><tt>[index.php]<b>Warning</b>: Event_Controller::include() [&lt;a href='function.include'&gt;function.include&lt;/a&gt;]: Failed opening 'hahahaha.php' for inclusion (include_path='.:/usr/share/php') in /www/htdocs/v027867/arena/event_controller.php at line 59</tt></font><br />
<font color="#ff0000" size="2pt"><tt>[PHP Error]<b>Warning</b>: Event_Controller::include() [&lt;a href='function.include'&gt;function.include&lt;/a&gt;]: Failed opening 'hahahaha.php' for inclusion (include_path='.:/usr/share/php') in /www/htdocs/v027867/arena/event_controller.php at line 59</tt></font><br />
<font color="#ff0000" size="2pt"><tt>[event_controller.php]<b>Warning</b>: Event_Controller::include() [&lt;a href='function.include'&gt;function.include&lt;/a&gt;]: Failed opening 'hahahaha.php' for inclusion (include_path='.:/usr/share/php') in /www/htdocs/v027867/arena/event_controller.php at line 59</tt></font><br />
<font color="#ff0000" size="2pt"><tt>[index.php]<b>Critical</b>: test</tt></font><br />
<font color="#ff0000" size="2pt"><tt>[PHP Error]<b>Critical</b>: test</tt></font><br />
<font color="#ff0000" size="2pt"><tt>[event_controller.php]<b>Critical</b>: test</tt></font><br />

Kann mir da jemand helfen?

Gruss
X
 
Hab mein Prob wiedermal selber lösen können. Anstat die statische Methode singleton habe ich factory verwenden. So funktionierts mal nicht schlecht. Auch wenn ich nicht ganz verstehe wieso es mit einem Singleton nicht funktionieren soll. Ich ruffe die funktion ja nur 1x mal auf. Naja...

Nun habe ich mal folgendes versucht...
PHP:
include("hahahaha.php");
$i = 1000 / 0;
$this->logger->crit("test", new Exception());

Ausgabe:
Code:
Warning: Division by zero in /www/htdocs/v027867/arena/event_controller.php on line 62

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /www/htdocs/v027867/arena/event_controller.php:62) in /www/htdocs/v027867/arena/index.php on line 61

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /www/htdocs/v027867/arena/event_controller.php:62) in /www/htdocs/v027867/arena/index.php on line 61
[event_controller.php]Debug: Event file [test] not found. Exception in /www/htdocs/v027867/arena/event_controller.php@82
[PHP Error]Warning: Event_Controller::include(hahahaha.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /www/htdocs/v027867/arena/event_controller.php at line 59
[PHP Error]Warning: Event_Controller::include(hahahaha.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /www/htdocs/v027867/arena/event_controller.php at line 59
[PHP Error]Warning: Event_Controller::include() [<a href='function.include'>function.include</a>]: Failed opening 'hahahaha.php' for inclusion (include_path='.:/usr/share/php') in /www/htdocs/v027867/arena/event_controller.php at line 59
[event_controller.php]Critical: test. Exception in /www/htdocs/v027867/arena/event_controller.php@61

Das die Division durch 0 einen Fehler hervorruft ist klar. Wie wird der aber nicht wie der Include von meinem Logger erfasst?
Komisch finde ich auch, dass das session_start() schon aufgerufen wurde, es hier jedoch einen Fehler gibt?

*grosses Fragezeichen*

Gruss
X
 
Zurück