1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class to Log messages. |
4
|
|
|
* |
5
|
|
|
* @author Vitex <[email protected]> |
6
|
|
|
* @copyright 2009-2019 [email protected] (G) |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Ease\Logger; |
10
|
|
|
|
11
|
|
|
class ToMemory extends \Ease\Atom implements Loggingable |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Předvolená metoda logování. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
public $logType = 'memory'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Adresář do kterého se zapisují logy. |
22
|
|
|
* |
23
|
|
|
* @var string dirpath |
24
|
|
|
*/ |
25
|
|
|
public $logPrefix = null; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Hodnoty pro obarvování logu. |
29
|
|
|
* |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
public $logStyles = [ |
33
|
|
|
'notice' => 'color: black;', |
34
|
|
|
'success' => 'color: #2C5F23;', |
35
|
|
|
'message' => 'color: #2C5F23;', |
36
|
|
|
'warning' => 'color: #AB250E;', |
37
|
|
|
'error' => 'color: red;', |
38
|
|
|
'debug' => 'font-style: italic;', |
39
|
|
|
'report' => 'font-wight: bold;', |
40
|
|
|
'info' => 'color: blue;', |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Odkaz na vlastnící objekt. |
45
|
|
|
* |
46
|
|
|
* @var \Ease\Sand |
47
|
|
|
*/ |
48
|
|
|
public $parentObject = null; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* ID naposledy ulozene zpravy. |
52
|
|
|
* |
53
|
|
|
* @var int unsigned |
54
|
|
|
*/ |
55
|
|
|
private $messageID = 0; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Saves obejct instace (singleton...). |
59
|
|
|
*/ |
60
|
|
|
private static $instance = null; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Pri vytvareni objektu pomoci funkce singleton (ma stejne parametry, jako |
64
|
|
|
* konstruktor) se bude v ramci behu programu pouzivat pouze jedna jeho |
65
|
|
|
* instance (ta prvni). |
66
|
|
|
* |
67
|
|
|
* @link http://docs.php.net/en/language.oop5.patterns.html Dokumentace a |
68
|
|
|
* priklad |
69
|
|
|
*/ |
70
|
|
|
public static function singleton() |
71
|
|
|
{ |
72
|
|
|
if (!isset(self::$instance)) { |
73
|
|
|
$class = __CLASS__; |
74
|
|
|
self::$instance = new $class(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return self::$instance; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Zapise zapravu do logu. |
82
|
|
|
* |
83
|
|
|
* @param string $caller název volajícího objektu |
84
|
|
|
* @param string $message zpráva |
85
|
|
|
* @param string $type typ zprávy (success|info|error|warning|*) |
86
|
|
|
* |
87
|
|
|
* @return bool byl report zapsán ? |
88
|
|
|
*/ |
89
|
|
|
public function addToLog($caller, $message, $type = 'message') |
90
|
|
|
{ |
91
|
|
|
++$this->messageID; |
92
|
|
|
$this->statusMessages[$type][$this->messageID] = $message; |
93
|
|
|
return true; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Vrací styl logování. |
98
|
|
|
* |
99
|
|
|
* @param string $logType typ logu warning|info|success|error|notice|* |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getLogStyle($logType = 'notice') |
104
|
|
|
{ |
105
|
|
|
if (key_exists($logType, $this->logStyles)) { |
106
|
|
|
return $this->logStyles[$logType]; |
107
|
|
|
} else { |
108
|
|
|
return ''; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|