Skip to content

Commit c739d2c

Browse files
committed
GD-18 adding watchog logging settings
1 parent d76e5b3 commit c739d2c

File tree

6 files changed

+55
-59
lines changed

6 files changed

+55
-59
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Settings are available under `/admin/config/system/os2logging/settings`
2424
* **Store database logs for this period** - Database logs will be stored for the selected number of days, after that they will be automatically deleted (cleanup is done daily).
2525
* **Store log files for this period** - Log file will be stored for the selected number of days, after that they will be automatically deleted
2626
* **Store log files directory** - Logs will be saved in this path.
27+
* **Import logs from uploaded file** - Allows import logs into database.
28+
29+
Settings are available under `/admin/config/system/os2logging/watchdog-settings`
30+
* **DB Log enabled** - If watchdog messages shall be added to the dblog.
31+
* **Store log files for this period** - Log file will be stored for the selected number of days, after that they will be automatically deleted
32+
* **Store log files directory** - Logs will be saved in this path.
2733

2834
## Install
2935

config/install/views.view.os2web_logging_access_logs.yml

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ dependencies:
44
config:
55
- system.menu.admin
66
module:
7-
- better_exposed_filters
87
- node
98
- os2web_logging
109
- user
@@ -38,7 +37,7 @@ display:
3837
query_comment: ''
3938
query_tags: { }
4039
exposed_form:
41-
type: bef
40+
type: basic
4241
options:
4342
submit_button: Udfør
4443
reset_button: false
@@ -47,47 +46,6 @@ display:
4746
expose_sort_order: true
4847
sort_asc_label: Asc
4948
sort_desc_label: Desc
50-
text_input_required: 'Vælg et filter og klik på Anvend for at se resultater'
51-
text_input_required_format: wysiwyg_tekst
52-
bef:
53-
general:
54-
autosubmit: false
55-
autosubmit_exclude_textfield: false
56-
autosubmit_textfield_delay: 500
57-
autosubmit_hide: false
58-
input_required: false
59-
allow_secondary: false
60-
secondary_label: 'Avancerede indstillinger'
61-
secondary_open: false
62-
filter:
63-
combine:
64-
plugin_id: default
65-
advanced:
66-
placeholder_text: ''
67-
collapsible: false
68-
is_secondary: false
69-
name:
70-
plugin_id: default
71-
advanced:
72-
placeholder_text: ''
73-
collapsible: false
74-
is_secondary: false
75-
ip:
76-
plugin_id: default
77-
advanced:
78-
placeholder_text: ''
79-
collapsible: false
80-
is_secondary: false
81-
created:
82-
plugin_id: default
83-
advanced:
84-
collapsible: false
85-
is_secondary: false
86-
created_1:
87-
plugin_id: default
88-
advanced:
89-
collapsible: false
90-
is_secondary: false
9149
pager:
9250
type: full
9351
options:
@@ -720,7 +678,7 @@ display:
720678
exposed: true
721679
expose:
722680
operator_id: created_op
723-
label: From
681+
label: Period
724682
description: ''
725683
use_operator: false
726684
operator: created_op
@@ -734,21 +692,26 @@ display:
734692
authenticated: authenticated
735693
anonymous: '0'
736694
administrator: '0'
695+
editor: '0'
696+
webmaster: '0'
737697
placeholder: ''
738698
min_placeholder: ''
739699
max_placeholder: ''
740700
is_grouped: false
741701
group_info:
742-
label: ''
743-
description: ''
744-
identifier: ''
702+
label: Created
703+
description: null
704+
identifier: created
745705
optional: true
746706
widget: select
747707
multiple: false
748708
remember: false
749709
default_group: All
750710
default_group_multiple: { }
751-
group_items: { }
711+
group_items:
712+
1: { }
713+
2: { }
714+
3: { }
752715
entity_type: os2web_logging_access_log
753716
entity_field: created
754717
plugin_id: date
@@ -769,7 +732,7 @@ display:
769732
exposed: true
770733
expose:
771734
operator_id: created_1_op
772-
label: To
735+
label: ''
773736
description: ''
774737
use_operator: false
775738
operator: created_1_op
@@ -783,6 +746,8 @@ display:
783746
authenticated: authenticated
784747
anonymous: '0'
785748
administrator: '0'
749+
editor: '0'
750+
webmaster: '0'
786751
placeholder: ''
787752
min_placeholder: ''
788753
max_placeholder: ''

os2web_logging.install

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
<?php
22

3+
use Symfony\Component\Yaml\Yaml;
4+
5+
/**
6+
* Helper function to update configuration.
7+
*
8+
* @param $config_name
9+
* String.
10+
*/
11+
function os2web_logging_read_in_new_config($config_name) {
12+
$path = drupal_get_path('module', 'os2web_logging');
13+
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
14+
$active_storage = \Drupal::service('config.storage');
15+
$active_storage->write($config_name, Yaml::parse(file_get_contents($path . '/config/install/' . $config_name . '.yml')));
16+
}
17+
318
/**
419
* Increase requiest_uri field length.
520
*/
@@ -17,3 +32,11 @@ function os2web_logging_update_8801() {
1732
function os2web_logging_update_8802() {
1833
\Drupal::service('module_installer')->uninstall(['date_popup']);
1934
}
35+
36+
/**
37+
* Updating logs search view.
38+
*/
39+
function os2web_logging_update_8803() {
40+
// Updating view.
41+
os2web_logging_read_in_new_config('views.view.os2web_logging_access_logs');
42+
}

src/Controller/LoggingController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,26 @@ public static function getCheckedRequirements() {
209209
*
210210
* @param string $filename
211211
* The filename.
212+
*
213+
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
214+
* File ready to be downloaded.
212215
*/
213216
public function logfileExport($filename) {
214217
$config = $this->config(SettingsForm::$configName);
215218

216-
// Do some file validation here, like checking for extension.
217-
218219
// File lives in /files/downloads.
219220
$logPath = $config->get('files_log_path');
220221

221-
$uri = $logPath . '/'. $filename;
222+
$uri = $logPath . '/' . $filename;
222223

223224
$headers = [
224-
'Content-Type' => 'text/csv', // Would want a condition to check for extension and set Content-Type dynamically
225+
'Content-Type' => 'text/plain',
225226
'Content-Description' => 'File Download',
226-
'Content-Disposition' => 'attachment; filename=' . $filename
227+
'Content-Disposition' => 'attachment; filename=' . $filename,
227228
];
228229

229230
// Return and trigger file donwload.
230-
return new BinaryFileResponse($uri, 200, $headers, true );
231-
231+
return new BinaryFileResponse($uri, 200, $headers, TRUE);
232232
}
233233

234234
}

src/Form/SettingsForm.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
134134
'#title' => $this->t('Store log files directory'),
135135
'#description' => $this->t('Log file will be stored for the selected number of days, after that they will be automatically deleted'),
136136
'#default_value' => $config->get('files_log_path') ? $config->get('files_log_path') : '../logs',
137+
'#field_suffix' => '<em>/os2web_logging_access_log-YYYY-MM-DD.log</em>',
137138
];
138139

139140
$form['logs_import_file_detail'] = [
@@ -144,9 +145,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
144145

145146
$options = [];
146147
if ($config->get('files_log_path')) {
147-
/** @var FileSystemInterface $fileSystem */
148+
/** @var Drupal\Core\File\FileSystemInterface $fileSystem */
148149
$fileSystem = \Drupal::service('file_system');
149-
$storedLogFiles = $fileSystem->scanDirectory($config->get('files_log_path'), '/os2web_logging_node_access-\d{4}-\d{2}-\d{2}\.(log|gz)/');
150+
$storedLogFiles = $fileSystem->scanDirectory($config->get('files_log_path'), '/os2web_logging_(node_access|access_log)-\d{4}-\d{2}-\d{2}\.(log|gz)/');
150151

151152
foreach ($storedLogFiles as $file) {
152153
$url = Url::fromRoute('os2web_logging.logfile.download', ['filename' => $file->filename]);

src/Form/WatchdogSettingsForm.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
8686
'#title' => $this->t('Store log files directory'),
8787
'#description' => $this->t('Log file will be stored for the selected number of days, after that they will be automatically deleted'),
8888
'#default_value' => $config->get('files_log_path') ?? '../logs',
89+
'#field_suffix' => '<em>/os2web_logging_watchdog-YYYY-MM-DD.log</em>',
8990
];
9091

9192
$options = [];
@@ -110,7 +111,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
110111
$watchlog_logs_rendered = \Drupal::service('renderer')->renderPlain($watchdog_logs_build);
111112

112113
$form['watchdog_files_details'][] = [
113-
'#markup' => $watchlog_logs_rendered
114+
'#markup' => $watchlog_logs_rendered,
114115
];
115116

116117
return parent::buildForm($form, $form_state);

0 commit comments

Comments
 (0)