Skip to content

Commit 56559dc

Browse files
committed
Merge branch 'master' into drupal9
2 parents 9e536cc + c739d2c commit 56559dc

12 files changed

+326
-71
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.info.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ core_version_requirement: ^8 || ^9
77
configure: os2web_logging.settings
88
dependencies:
99
- monolog
10-
- date_popup

os2web_logging.install

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
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+
18+
/**
19+
* Increase requiest_uri field length.
20+
*/
21+
function os2web_logging_update_8801() {
22+
$field_spec = [
23+
'type' => 'varchar',
24+
'length' => '500',
25+
];
26+
\Drupal::database()->schema()->changeField('os2web_logging_access_log','request_uri', 'request_uri', $field_spec);
27+
}
28+
29+
/**
30+
* Disable date_popup module.
31+
*/
32+
function os2web_logging_update_8802() {
33+
\Drupal::service('module_installer')->uninstall(['date_popup']);
34+
}
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+
}

os2web_logging.links.task.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ os2web_logging.settings:
22
title: Settings
33
route_name: os2web_logging.settings
44
base_route: os2web_logging.settings
5+
os2web_logging.watchdog_settings:
6+
title: Watchdog
7+
route_name: os2web_logging.watchdog_settings
8+
base_route: os2web_logging.settings
59
os2web_logging.status:
610
title: Status
711
route_name: os2web_logging.status

os2web_logging.module

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,3 @@ function _os2web_logging_send_status_failed_email(array $errors) {
214214
\Drupal::logger('os2web_logging')->warning(t('There was a problem sending email to %email', ['%email' => $siteMail]));
215215
}
216216
}
217-
218-
/**
219-
* Increase requiest_uri field lenght().
220-
*/
221-
function os2web_logging_update_8801() {
222-
$field_spec = [
223-
'type' => 'varchar',
224-
'length' => '500',
225-
];
226-
\Drupal::database()->schema()->changeField('os2web_logging_access_log','request_uri', 'request_uri', $field_spec);
227-
;
228-
}

os2web_logging.routing.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,18 @@ os2web_logging.settings:
1616
_permission: 'administer os2logging settings'
1717
options:
1818
_admin_route: TRUE
19+
os2web_logging.watchdog_settings:
20+
path: '/admin/config/system/os2logging/watchdog-settings'
21+
defaults:
22+
_form: '\Drupal\os2web_logging\Form\WatchdogSettingsForm'
23+
_title: 'OS2Web watchdog logging settings'
24+
requirements:
25+
_permission: 'administer os2logging settings'
26+
options:
27+
_admin_route: TRUE
28+
os2web_logging.logfile.download:
29+
path: '/os2web_logging/log/{filename}'
30+
defaults:
31+
_controller: '\Drupal\os2web_logging\Controller\LoggingController::logfileExport'
32+
requirements:
33+
_permission: 'administer os2logging settings'

os2web_logging.services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parameters:
22
monolog.channel_handlers:
33
# If not specified use the default handlers.
4-
default: ['os2web_logging_watchdog']
4+
default: ['os2web_logging_watchdog', 'drupal.dblog']
55
# Log php channel to web server's error log.
66
php: ['error_log']
77
os2web_logging.access_log:

src/Controller/LoggingController.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\Core\Controller\ControllerBase;
66
use Drupal\Core\File\FileSystemInterface;
77
use Drupal\os2web_logging\Form\SettingsForm;
8+
use Symfony\Component\HttpFoundation\BinaryFileResponse;
89

910
/**
1011
* Provides status page.
@@ -203,4 +204,31 @@ public static function getCheckedRequirements() {
203204
return $requirements;
204205
}
205206

207+
/**
208+
* Download file.
209+
*
210+
* @param string $filename
211+
* The filename.
212+
*
213+
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
214+
* File ready to be downloaded.
215+
*/
216+
public function logfileExport($filename) {
217+
$config = $this->config(SettingsForm::$configName);
218+
219+
// File lives in /files/downloads.
220+
$logPath = $config->get('files_log_path');
221+
222+
$uri = $logPath . '/' . $filename;
223+
224+
$headers = [
225+
'Content-Type' => 'text/plain',
226+
'Content-Description' => 'File Download',
227+
'Content-Disposition' => 'attachment; filename=' . $filename,
228+
];
229+
230+
// Return and trigger file donwload.
231+
return new BinaryFileResponse($uri, 200, $headers, TRUE);
232+
}
233+
206234
}

src/Form/SettingsForm.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
132132
$form['file_logs_detail']['files_log_path'] = [
133133
'#type' => 'textfield',
134134
'#title' => $this->t('Store log files directory'),
135-
'#description' => $this->t('Logs will be saved in this path'),
135+
'#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'] = [
@@ -142,19 +143,23 @@ public function buildForm(array $form, FormStateInterface $form_state) {
142143
->t('Logs import'),
143144
];
144145

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

149152
foreach ($storedLogFiles as $file) {
150-
$nodeTypeOptions[$file->uri] = $file->filename;
153+
$url = Url::fromRoute('os2web_logging.logfile.download', ['filename' => $file->filename]);
154+
$link = Link::fromTextAndUrl(t('[Download]'), $url);
155+
$options[$file->uri] = $file->filename . ' ' . $link->toString();
151156
}
152-
arsort($nodeTypeOptions);
157+
arsort($options);
153158
}
154159

155160
$form['logs_import_file_detail']['logs_import_files_select'] = [
156161
'#type' => 'checkboxes',
157-
'#options' => $nodeTypeOptions,
162+
'#options' => $options,
158163
'#title' => $this->t('Import from existing files'),
159164
'#description' => $this->t('Archived log files will be automatically extracted'),
160165
];

0 commit comments

Comments
 (0)