Location: PHPKode > projects > NmnLogger > NmnLogger1.1/NmnLoggerObject.php
<?php 
    /*
    NmnLogger is a library that provides logging functionnality to php applications
    Copyright (C) 2006  Ivan Preziosi from netmeans.net - Rome.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

    For more informations or to join the development of the library contact
    the author at: hide@address.com
    */

require_once "logger/NmnLoggerConfig.php";

/**
 * This is the main class of the package.
 * 
 * @author  Ivan Preziosi <hide@address.com>
 * @version 1.1
 * @since   NmnLogger 0.5
 * @package NmnLogger
 *
 */
Class NmnLoggerObject{

	/**
	* config object, holds the configuration parsed from xml file.
	*/
	private $config;

	/**
	* path where the configuration xml file is located.
	*/
	private $configPath;

	/**
	* family this logger instance belongs to.
	*/
	private $family;


	/**
	* Expects the location of the config file and the family this istance belongs to.
	*/
	public function __construct($myConfigPath = 'logger/nmn-logger-config.xml',$myFamily = 'default'){
		$this->configPath = $myConfigPath;
		$this->family = $myFamily;
		try{
			$this->config = new NmnLoggerConfig($this->configPath,$this->family);
		}catch(Exception $ex){
			echo $ex->getMessage();
		}
	}

	/**
	* This function is used to deliver message objects created from messageFactories
	* to all the devices configured in this family
	*/
	private function dispatchMessage($msg){
		$devices = $this->config->getDevices();
		foreach ($devices as $device){			
			if ((int)$device->getLevel() <= $msg->getLevel()){
				foreach ($device->getDrivers() as $driverObj){
					$driverObj->doLog($msg);
				}
			}
		}
	}

	/**
	* Used to log an Exception directly to the devices of the active family.
	 * @param Exception $e the exception to be logged
	 * @param Integer $level	the priority level of the message
	*/
	public function logException($e,$logLevel = 1){
		try{
			$logMessage = $this->config->getMessageFactory();
			$logMessage->setLogLevel($logLevel);
			$logMessage->setException($e);
			$this->dispatchMessage($logMessage);
		}catch(Exception $ex){
			echo $ex->getMessage();
		}
	}

	/**
	* Used to log a message string directly to the devices of the active family.
	* @param Mixed $msg	the priority level of the message
	* @param Integer $level	the priority level of the message
	*/
	public function logString($msg,$logLevel = 1){
		try{
			$logMessage = $this->config->getMessageFactory();
			$logMessage->setLogLevel($logLevel);
			$logMessage->setMessage($msg);
			$this->dispatchMessage($logMessage);
		}catch(Exception $ex){
			echo $ex->getMessage();
		}
	}

	



}


?>
Return current item: NmnLogger