-
Notifications
You must be signed in to change notification settings - Fork 275
/
LoggingConfigForm.php
119 lines (112 loc) · 4.67 KB
/
LoggingConfigForm.php
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
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Forms\Config\General;
use Icinga\Application\Logger;
use Icinga\Web\Form;
class LoggingConfigForm extends Form
{
/**
* Initialize this form
*/
public function init()
{
$this->setName('form_config_general_logging');
}
/**
* (non-PHPDoc)
* @see Form::createElements() For the method documentation.
*/
public function createElements(array $formData)
{
$this->addElement(
'select',
'logging_log',
array(
'required' => true,
'autosubmit' => true,
'label' => $this->translate('Logging Type'),
'description' => $this->translate('The type of logging to utilize.'),
'multiOptions' => array(
'syslog' => 'Syslog',
'file' => $this->translate('File', 'app.config.logging.type'),
'none' => $this->translate('None', 'app.config.logging.type')
)
)
);
if (! isset($formData['logging_log']) || $formData['logging_log'] !== 'none') {
$this->addElement(
'select',
'logging_level',
array(
'required' => true,
'label' => $this->translate('Logging Level'),
'description' => $this->translate('The maximum logging level to emit.'),
'multiOptions' => array(
Logger::$levels[Logger::ERROR] => $this->translate('Error', 'app.config.logging.level'),
Logger::$levels[Logger::WARNING] => $this->translate('Warning', 'app.config.logging.level'),
Logger::$levels[Logger::INFO] => $this->translate('Information', 'app.config.logging.level'),
Logger::$levels[Logger::DEBUG] => $this->translate('Debug', 'app.config.logging.level')
)
)
);
}
if (false === isset($formData['logging_log']) || $formData['logging_log'] === 'syslog') {
$this->addElement(
'text',
'logging_application',
array(
'required' => true,
'label' => $this->translate('Application Prefix'),
'description' => $this->translate(
'The name of the application by which to prefix syslog messages.'
),
'requirement' => $this->translate('The application prefix must not contain whitespace.'),
'value' => 'icingaweb2',
'validators' => array(
array(
'Regex',
false,
array(
'pattern' => '/^[^\W]+$/',
'messages' => array(
'regexNotMatch' => $this->translate(
'The application prefix must not contain whitespace.'
)
)
)
)
)
)
);
/*
* Note(el): Since we provide only one possible value for the syslog facility, I opt against exposing
* this configuration.
*/
// $this->addElement(
// 'select',
// 'logging_facility',
// array(
// 'required' => true,
// 'label' => $this->translate('Facility'),
// 'description' => $this->translate('The syslog facility to utilize.'),
// 'multiOptions' => array(
// 'user' => 'LOG_USER'
// )
// )
// );
} elseif (isset($formData['logging_log']) && $formData['logging_log'] === 'file') {
$this->addElement(
'text',
'logging_file',
array(
'required' => true,
'label' => $this->translate('File path'),
'description' => $this->translate('The full path to the log file to write messages to.'),
'value' => '/var/log/icingaweb2/icingaweb2.log',
'validators' => array('WritablePathValidator')
)
);
}
return $this;
}
}