Location: PHPKode > projects > Katyshop > katyshop_ro_0.3.2.1/classes/common/Logger.php
<?php

/**
 * Product: Katyshop
 * @version 0.3.2.1
 * @author Catalin Hulea - hide@address.com
 * @copyright Copyright (C) 2007 Catalin Hulea
 * @license GNU General Public License version 3
 * 			You can find a copy of GNU GPL v3 at this path: /docs/LICENSE
 * @link https://sourceforge.net/projects/katyshop
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

require_once(dirname(__FILE__) . "/BaseClass.php");

class Logger extends BaseClass
{
	/**
	 * Example:
	 * Logger::str("Hello World!", __FILE__, __LINE__);
	 * log anything. This is called by Logger::err and Logger::msg too.
	 */
	function str($s, $file = "", $line = "")
	{
		$cfgLog = Application::getConfigValue("logger");
		$s = "[" . $line . "] " . $s;
		$s = "[" . basename($file) . "] " . $s;
		$s = "[" . date("Y-m-d H:i:s") . "] " . $s;
		if(@$cfgLog["active"])
		{
			$f = @fopen(DATA_DIR . "/logs/" . @$cfgLog["filename"], "a+");
			@fwrite($f, $s . "\r\n");
			@fclose($f);
		}
	}

	/**
	 * log request; similar to apache log files, but has the capability also to log _POST data
	 */
	function request($bubble = false)
	{
		$cfgLog = Application::getConfigValue("logger");

		$file = $_SERVER['REQUEST_URI'];
		$arr = parse_url(BASE_HREF);
		$file = str_replace($arr["path"], "", $file);

		$s = "REQUEST_URI = ";
		$s .= $file;
		if($_POST)
		{
			$s .= "\r\n _POST = ";
			$s .= print_r($_POST, true);
		}
		$s = "[" . $_SERVER['REMOTE_ADDR'] . "] " . $s;
		$s = "[" . date("Y-m-d H:i:s") . "] " . $s;
		if($bubble)
			Logger::str($s);
		if(@$cfgLog["request_active"])
		{
			$f = @fopen(DATA_DIR . "/logs/" . @$cfgLog["request_filename"], "a+");
			@fwrite($f, $s . "\r\n");
			@fclose($f);
		}
	}

	/**
	 * Example:
	 * Logger::err("Oh no!", __FILE__, __LINE__);
	 * log an error.
	 */
	function err($s, $file = "", $line = "")
	{
		Logger::str($s, $file, $line);

		$cfgLog = Application::getConfigValue("logger");
		$s = "[" . $line . "] " . $s;
		$s = "[" . basename($file) . "] " . $s;
		$s = "[" . date("Y-m-d H:i:s") . "] " . $s;
		if(@$cfgLog["errors_active"])
		{
			$f = @fopen(DATA_DIR . "/logs/" . @$cfgLog["errors_filename"], "a+");
			@fwrite($f, $s . "\r\n");
			@fclose($f);
		}
	}

	/**
	 * Example:
	 * Logger::msg("I love you :)", __FILE__, __LINE__);
	 * log a message
	 */
	function msg($s, $file = "", $line = "")
	{
		Logger::str($s, $file, $line);

		$cfgLog = Application::getConfigValue("logger");
		$s = "[" . $line . "] " . $s;
		$s = "[" . basename($file) . "] " . $s;
		$s = "[" . date("Y-m-d H:i:s") . "] " . $s;
		if(@$cfgLog["messages_active"])
		{
			$f = @fopen(DATA_DIR . "/logs/" . @$cfgLog["messages_filename"], "a+");
			@fwrite($f, $s . "\r\n");
			@fclose($f);
		}
	}

	/**
	 * Example:
	 * $x = new SomeObject();
	 * Logger::vardump($x, "x", __FILE__, __LINE__)
	 * log dump of a variable
	 */
	function vardump($value, $varName = "some variable", $file = "", $line = "")
	{
		$value = Tools::remove_keys($value, array("db", "cfg", "mailAgent"));

		$s = $varName . " = " . print_r($value, true);
		Logger::str($s, $file, $line);

		$cfgLog = Application::getConfigValue("logger");
		$s = "[" . $line . "] " . $s;
		$s = "[" . basename($file) . "] " . $s;
		$s = "[" . date("Y-m-d H:i:s") . "] " . $s;
		if(@$cfgLog["vardump_active"])
		{
			$f = @fopen(DATA_DIR . "/logs/" . @$cfgLog["vardump_filename"], "a+");
			@fwrite($f, $s . "\r\n");
			@fclose($f);
		}
	}

}
?>
Return current item: Katyshop