/application/classes/Dlog.php
PHP | 120 lines | 72 code | 13 blank | 35 comment | 5 complexity | 5922e649fabc1a163f46a94ef0965b72 MD5 | raw file
Possible License(s): LGPL-2.1, MIT, BSD-3-Clause
- <?php
- /**
- * Database logger
- *
- * @package zeptocms
- * @version 2012/11/13
- * @author Chris Piechowicz <info@zeptocms.com>
- */
- class Dlog
- {
- const TABLE = "logs";
-
- // log levels
- const SUCCESS = 1;
- const NOTICE = 2;
- const WARNING = 3;
- const ERROR = 4;
-
- // database instance
- protected static $db = FALSE;
-
- // current app area
- protected static $area = "site";
-
- /**
- * Add log item
- *
- * @param string $type log type (success, error, etc.)
- * @param string $title message title
- * @param string $description message description
- * @param string $debug additional information for developer
- */
- public static function add($type, $title, $description = NULL, $debug = NULL)
- {
- // check if logging enabled
- if (!Config::sys("log/enable") || $type > Config::sys("log/level"))
- return FALSE;
-
- if (!self::$db)
- self::$db = new Model_Db;
-
- $row = array(
-
- "adddate" => Date::now(),
- "type" => $type,
- "area" => Dlog::area(),
- "title" => $title,
- "description" => $description,
- "debug" => $debug
-
- );
-
- self::$db->addRow(self::TABLE, $row);
- }
-
- /**
- * Get current area
- *
- * @return string
- */
- public static function area()
- {
- return self::$area;
- }
-
- /**
- * Set current area
- *
- * @param string $area
- */
- public static function setCurrentArea($area)
- {
- self::$area = $area;
- }
-
- /**
- * Get log level name
- *
- * @param int $level level name
- * @return string
- */
- public static function getLevelName($level)
- {
- switch ($level)
- {
- case 1:
- return "success";
- break;
- case 2:
- return "notice";
- break;
- case 3:
- return "warning";
- break;
- case 4:
- return "error";
- break;
- }
- }
-
- public static function getLevelIcon($level)
- {
- switch ($level)
- {
- case 1:
- return HTML::image("res/img/admin/log/success.png", array("alt" => "success"));
- break;
- case 2:
- return HTML::image("res/img/admin/log/notice.png", array("alt" => "notice"));
- break;
- case 3:
- return HTML::image("res/img/admin/log/warning.png", array("alt" => "warning"));
- break;
- case 4:
- return HTML::image("res/img/admin/log/error.png", array("alt" => "error"));
- break;
- }
- }
- }
- ?>