Error: Class 'Logger' not found

Hey there,

I’m trying to extend the Log-Class as I want to save some more information.

So I extended YiiBase and CLogger, atleast to the point where i get the following errormsg:

“Fatal error: Class ‘Logger’ not found in C:\Users\rien\webflow3\framework\yii.php on line 40”

My Yii class:


class Yii extends YiiBase

{

	private static $_logger;


	public static function log($msg,$level=CLogger::LEVEL_INFO,$category='application')

	{

		if(self::$_logger===null)

			self::$_logger=new Logger;

		self::$_logger->log($msg,$level,$category,'test');

	}


	/**

	 * @return Logger message logger

	 */

	public static function getLogger()

	{

		if(self::$_logger!==null)

			return self::$_logger;

		else

			return self::$_logger=new Logger;

	}


}

My Logger class:


class Logger extends CLogger

{


	public function log($message,$level='info',$category='application',$user)

	{

		$this->_logs[]=array($message,$level,$category,$user,$this->server,microtime(true));

		$this->_logCount++;

		if($this->autoFlush>0 && $this->_logCount>=$this->autoFlush && !$this->_processing)

		{

			$this->_processing=true;

			$this->flush($this->autoDump);

			$this->_processing=false;

		}

	}


}

I know there are still some things wrong, but those shouldnt be the things giving me the error.

I can’t figure out why this error occurs, can u help me?

PHP5.4,Apache2.4,Yii1.1.x

regards

I think the following will make it work:




class Yii extends YiiBase

{

        private static $_logger;


        public static function log($msg,$level=CLogger::LEVEL_INFO,$category='application')

        {

                // Not sure why you were doing this:

                //if(self::$_logger===null)

                //        self::$_logger=new Logger;

                //self::$_logger->log($msg,$level,$category,'test');


                self::getLogger()->log($msg,$level,$category,'test');

        }


        /**

         * @return Logger message logger

         */

        public static function getLogger()

        {

                if(self::$_logger!==null)

                {

                        return self::$_logger;

                }

                else

                {

                        self::import('application.path.to.logger');

                        return self::$_logger=new Logger;

                }

        }


}



I don’t think you can safely list the file to be imported in the config file, because the system might try to log something before the config has been processed. I’m not sure about this though.

Hey,

thanks for your response!

Actually I found another way which is probably better:

I extended CDbLogRoute and I was able to add my additional stuff there.

Thanks anyways :)