Yii Framework Forum: CApplication onException / onError to be raised before logging - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CApplication onException / onError to be raised before logging so the log message could be modified / extended. Rate Topic: -----

#1 User is offline   migajek 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 15-November 09

Posted 29 May 2012 - 06:28 AM

Hi,
current implementation of handleError method logs the error message at first, and then raises an event.
I believe the order should be reversed, so that one might extend the logged error message.

Let's assume I want to assign each error occurrence an unique ID, which is displayed to user, so he might contact the developer providing the error code.

currently I'm just logging the error code in onError handler
    'onError' => function($ev) {
        $ev->params['uniqid'] = uniqid();
        Yii::log($ev->params['uniqid'], 'error');
    },

but under heavy load the order might be lost (assuming two separate requests being processed at once)

I'd love to do so:
        $ev->message = $ev->params['uniqid'] . ': '. $ev->message;





here's my proposition to modify the handleError()
			// disable error capturing to avoid recursive errors
			restore_error_handler();
			restore_exception_handler();
			// modifications begin
			try
			{
				Yii::import('CErrorEvent',true);
				$event=new CErrorEvent($this,$code,$message,$file,$line);
				$this->onError($event);
				if(!$event->handled)
				{
					// try an error handler
					if(($handler=$this->getErrorHandler())!==null)
						$handler->handle($event);
					else
						$this->displayError($code,$message,$file,$line);
				}
			}
			catch(Exception $e)
			{
				$this->displayException($e);
			}

			$log="{$event->message} ($file:$line)\nStack trace:\n";
// end of modifications
			$trace=debug_backtrace();

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users