Return to Snippet

Revision: 28131
at July 1, 2010 22:36 by orenus


Initial Code
//a better way...
class MyLogger {
	
	private $ipAddr;
	
	public function MyLogger(){
		
	}
	
	public function logDebug($sMsg){
		$this->writeLog("DEBUG", $sMsg);
	}
	
	public function logError($sMsg){
		$this->writeLog("ERROR", $sMsg);
	}
	
	public function logInfo($sMsg){
		$this->writeLog("INFO", $sMsg);
	}
	
	private function writeLog($sSevirity, $sMsg){
		error_log("[". $this->getClientIP() ."] :: ". date("j/n/y H:i:s") . $sSevirity .": ". $sMsg);
	}
	
	private function getClientIP(){
		if (!$this->$ipAddr) {
			if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
			   $this->$ipAddr=$_SERVER['HTTP_X_FORWARDED_FOR'];
			}
			else
			if ($_SERVER['HTTP_CLIENT_IP']) {
			   $this->$ipAddr=$_SERVER['HTTP_CLIENT_IP'];
			}
			else
				$this->$ipAddr= $_SERVER['REMOTE_ADDR'];
		}

		return $this->$ipAddr;
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
Lesson 3 -  Step 2 - encapsulation

Initial Tags

                                

Initial Language
PHP