1 <?php
2
3 namespace rpf\system\module;
4
5 class log
6 {
7 protected static function add($level, $desc, $context = NULL, $param = NULL)
8 {
9 $dir = __DIR__.'/../../../logs/';
10 $file = $dir.'syslog_'.date("ymd").'_1SRV.log';
11
12 $text = str_pad('['.date("r",time())."] [$level]", 41);
13 if (RPF_DEBUG == true)
14 {
15 $context = strpos($context, ')') === false ? $context.'()' : $context;
16 $text = str_pad("$text $context;", 120)."// $desc";
17
18 if (\is_array($param) && count($param) == 1)
19 {
20 foreach ($param as $name => $value)
21 {
22 $text .= " | $name: $value";
23 }
24 }
25 elseif (is_array($param) || is_object($param))
26 {
27
28
29 }
30 elseif (!empty($param))
31 {
32 $text .= " | $param";
33 }
34 }
35 else
36 {
37 $text .= $desc;
38 }
39 $text .= "\n";
40
41 $fp = fopen($file, 'a');
42 fwrite($fp, $text);
43 fclose($fp);
44 return true;
45 }
46
47 public static function debug($desc, $context, $array = NULL)
48 {
49 if (RPF_DEBUG == true)
50 {
51 return self::add(__FUNCTION__, $desc, $context, $array);
52 }
53 else
54 {
55 return true;
56 }
57 }
58
59 public static function notice($desc, $context, $array = NULL)
60 {
61 return self::add(__FUNCTION__, $desc, $context, $array);
62 }
63
64 public static function info($desc, $context, $array = NULL)
65 {
66 return self::add(__FUNCTION__, $desc, $context, $array);
67 }
68
69 public static function warning($desc, $context, $array = NULL)
70 {
71 return self::add(__FUNCTION__, $desc, $context, $array);
72 }
73
74 public static function error($desc, $context, $array = NULL)
75 {
76 return self::add(__FUNCTION__, $desc, $context, $array);
77 }
78 }