PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 37ms app.codeStats 0ms

/application/classes/Dlog.php

https://bitbucket.org/chrispiechowicz/zepto
PHP | 120 lines | 72 code | 13 blank | 35 comment | 5 complexity | 5922e649fabc1a163f46a94ef0965b72 MD5 | raw file
  1<?php
  2    /**
  3     * Database logger
  4     * 
  5     * @package     zeptocms
  6     * @version     2012/11/13
  7	 * @author		Chris Piechowicz <info@zeptocms.com>
  8     */
  9	class Dlog
 10	{
 11		const TABLE = "logs";
 12		
 13		// log levels
 14        const SUCCESS = 1;
 15        const NOTICE  = 2;
 16        const WARNING = 3;
 17        const ERROR   = 4;		
 18		
 19		// database instance
 20		protected static $db = FALSE;
 21		
 22		// current app area
 23		protected static $area = "site"; 
 24		
 25		/**
 26		 * Add log item
 27		 * 
 28		 * @param	string	$type			log type (success, error, etc.)
 29		 * @param	string	$title			message title
 30		 * @param	string	$description	message description
 31		 * @param	string	$debug			additional information for developer
 32		 */
 33		public static function add($type, $title, $description = NULL, $debug = NULL)
 34		{
 35			// check if logging enabled
 36            if (!Config::sys("log/enable") || $type > Config::sys("log/level")) 
 37                return FALSE;  			
 38			
 39			if (!self::$db)
 40				self::$db = new Model_Db;
 41			
 42			$row = array(
 43			
 44				"adddate"		=> Date::now(),
 45				"type"			=> $type,
 46				"area"			=> Dlog::area(),
 47				"title"			=> $title,
 48				"description"	=> $description,
 49				"debug"			=> $debug
 50			
 51			);
 52						
 53			self::$db->addRow(self::TABLE, $row);
 54		}
 55		
 56		/**
 57		 * Get current area
 58		 * 
 59		 * @return	string
 60		 */
 61		public static function area()
 62		{
 63			return self::$area;
 64		}
 65		 
 66		 /**
 67		  * Set current area
 68		  * 
 69		  * @param	string	$area
 70		  */
 71		 public static function setCurrentArea($area)
 72		 {
 73		 	self::$area = $area;
 74		 }
 75		 
 76		 /**
 77		  * Get log level name
 78		  * 
 79		  * @param	int		$level	level name
 80		  * @return	string
 81		  */
 82		 public static function getLevelName($level)
 83		 {
 84		 	switch ($level)
 85			{
 86				case 1:
 87						return "success";
 88						break;
 89				case 2:
 90						return "notice";
 91						break;
 92				case 3:
 93						return "warning";
 94						break;
 95				case 4:
 96						return "error";
 97						break;																		
 98			}
 99		 }
100		 
101		 public static function getLevelIcon($level)
102		 {
103		 	switch ($level)
104			{
105				case 1:
106						return HTML::image("res/img/admin/log/success.png", array("alt" => "success"));
107						break;
108				case 2:
109						return HTML::image("res/img/admin/log/notice.png", array("alt" => "notice"));
110						break;
111				case 3:
112						return HTML::image("res/img/admin/log/warning.png", array("alt" => "warning"));
113						break;
114				case 4:
115						return HTML::image("res/img/admin/log/error.png", array("alt" => "error"));
116						break;																		
117			}		 	
118		 }
119	}
120?>