|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Provides logging functionality |
|
5
|
|
|
* |
|
6
|
|
|
* PHP Version 5 |
|
7
|
|
|
* |
|
8
|
|
|
* @category Core |
|
9
|
|
|
* @package Logs |
|
10
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
|
11
|
|
|
* @copyright 2013 cSphere Team |
|
12
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
13
|
|
|
* @link http://www.csphere.eu |
|
14
|
|
|
**/ |
|
15
|
|
|
|
|
16
|
|
|
namespace csphere\core\logs; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Provides logging functionality |
|
20
|
|
|
* |
|
21
|
|
|
* @category Core |
|
22
|
|
|
* @package Logs |
|
23
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
|
24
|
|
|
* @copyright 2013 cSphere Team |
|
25
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
26
|
|
|
* @link http://www.csphere.eu |
|
27
|
|
|
**/ |
|
28
|
|
|
|
|
29
|
|
|
abstract class Base extends \csphere\core\service\Drivers |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Stores the logging content |
|
33
|
|
|
**/ |
|
34
|
|
|
protected $channels = []; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Mails the log content |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $component Name of the core component |
|
40
|
|
|
* @param string $content Content to log in this case |
|
41
|
|
|
* |
|
42
|
|
|
* @return void |
|
43
|
|
|
**/ |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
private function _mail($component, $content) |
|
46
|
|
|
{ |
|
47
|
|
|
$mail = $this->loader->load('mail'); |
|
48
|
|
|
|
|
49
|
|
|
$mail->prepare('Log entry: ' . $component, $content); |
|
50
|
|
|
|
|
51
|
|
|
// Only send mail when there is a mail_to set |
|
52
|
|
|
if (!empty($this->config['mail_to'])) { |
|
53
|
|
|
|
|
54
|
|
|
$mail->send($this->config['mail_to']); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns a formatted array with statistics |
|
60
|
|
|
* |
|
61
|
|
|
* @return array |
|
62
|
|
|
**/ |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
public function info() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->channels; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Logs the content for the component of choice |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $component Name of the core component |
|
73
|
|
|
* @param string $content Content to log in this case |
|
74
|
|
|
* @param boolean $store Defaults to true which enables log files |
|
75
|
|
|
* @param string $append Append a string only for log files |
|
76
|
|
|
* |
|
77
|
|
|
* @return void |
|
78
|
|
|
**/ |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
public function log($component, $content, $store = true, $append = '') |
|
81
|
|
|
{ |
|
82
|
|
|
// Create array element for component if not done so far |
|
83
|
|
|
if (empty($this->channels[$component])) { |
|
84
|
|
|
|
|
85
|
|
|
$this->channels[$component] = []; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// Add entry to live log |
|
89
|
|
|
$this->channels[$component][] = $content; |
|
90
|
|
|
|
|
91
|
|
|
// Store entry if enabled and true |
|
92
|
|
|
if ($store == true && isset($this->config['save'][$component])) { |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
$this->store($component, $content . $append); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
// Mail entry if enabled |
|
98
|
|
|
if (isset($this->config['mail'][$component])) { |
|
99
|
|
|
|
|
100
|
|
|
$this->_mail($component, $content . $append); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Stores the log content for later usage |
|
106
|
|
|
* |
|
107
|
|
|
* @param string $component Name of the core component |
|
108
|
|
|
* @param string $content Content to log in this case |
|
109
|
|
|
* |
|
110
|
|
|
* @return boolean |
|
111
|
|
|
**/ |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
abstract protected function store($component, $content); |
|
114
|
|
|
} |
|
115
|
|
|
|