1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 | <?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;
}
}
}
?>
|