1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Server\Configuration\LoggerJsonConfiguration |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Johann Zelger <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/server |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Server\Configuration; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Server\Interfaces\LoggerConfigurationInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class LoggerJsonConfiguration |
27
|
|
|
* |
28
|
|
|
* @author Johann Zelger <[email protected]> |
29
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
31
|
|
|
* @link https://github.com/appserver-io/server |
32
|
|
|
* @link http://www.appserver.io |
33
|
|
|
*/ |
34
|
|
|
class LoggerJsonConfiguration implements LoggerConfigurationInterface |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Holds the data instance read by json file |
39
|
|
|
* |
40
|
|
|
* @var \stdClass |
41
|
|
|
*/ |
42
|
|
|
protected $data; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Holds the handlers data |
46
|
|
|
* |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
protected $handlers; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Holds the processors data |
53
|
|
|
* |
54
|
|
|
* @var array |
55
|
|
|
*/ |
56
|
|
|
protected $processors; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Constructs config |
60
|
|
|
* |
61
|
|
|
* @param \stdClass $data The data object |
62
|
|
|
*/ |
63
|
|
|
public function __construct(\stdClass $data) |
64
|
|
|
{ |
65
|
|
|
// set data |
66
|
|
|
$this->data = $data; |
67
|
|
|
|
68
|
|
|
// prepare handlers |
69
|
|
|
$this->handlers = $this->prepareHandlers($data); |
70
|
|
|
// prepare processors |
71
|
|
|
$this->processors = $this->prepareProcessors($data); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Returns name |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getName() |
80
|
|
|
{ |
81
|
|
|
return $this->data->name; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns type |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getType() |
90
|
|
|
{ |
91
|
|
|
return $this->data->type; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Returns channel |
96
|
|
|
* |
97
|
|
|
* @return string|null |
98
|
|
|
*/ |
99
|
|
|
public function getChannel() |
100
|
|
|
{ |
101
|
|
|
// check if channel is given |
102
|
|
|
if (isset($this->data->channel)) { |
103
|
|
|
return $this->data->channel; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns defined handlers for logger |
109
|
|
|
* |
110
|
|
|
* @return array |
111
|
|
|
*/ |
112
|
|
|
public function getHandlers() |
113
|
|
|
{ |
114
|
|
|
return $this->handlers; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Returns defined processors for logger |
119
|
|
|
* |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
|
|
public function getProcessors() |
123
|
|
|
{ |
124
|
|
|
return $this->processors; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Prepares handlers array for config |
129
|
|
|
* |
130
|
|
|
* @param \stdClass $data The data object get information from |
131
|
|
|
* |
132
|
|
|
* @return array |
133
|
|
|
*/ |
134
|
|
|
public function prepareHandlers(\stdClass $data) |
135
|
|
|
{ |
136
|
|
|
$handlers = array(); |
137
|
|
|
if ($data->handlers) { |
138
|
|
|
foreach ($data->handlers as $handler) { |
139
|
|
|
// build up params |
140
|
|
|
$params = (array)$handler->params; |
141
|
|
|
// set up handler infos |
142
|
|
|
$handlers[$handler->type]['params'] = $params; |
143
|
|
|
// build up formatter infos if exists |
144
|
|
|
if (isset($handler->formatter)) { |
145
|
|
|
$formatterType = $handler->formatter->type; |
146
|
|
|
$formatterParams = (array)$handler->formatter->params; |
147
|
|
|
// setup formatter info |
148
|
|
|
$handlers[$handler->type]['formatter'] = array( |
149
|
|
|
'type' => $formatterType, |
150
|
|
|
'params' => $formatterParams |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
return $handlers; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Prepares processors array for config |
160
|
|
|
* |
161
|
|
|
* @param \stdClass $data The data object get information from |
162
|
|
|
* |
163
|
|
|
* @return array |
164
|
|
|
*/ |
165
|
|
|
public function prepareProcessors(\stdClass $data) |
166
|
|
|
{ |
167
|
|
|
$processors = array(); |
168
|
|
|
if (isset($data->processors)) { |
169
|
|
|
foreach ($data->processors as $processor) { |
170
|
|
|
$processors[$processor->type] = $processor->type; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
return $processors; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|