File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 31
31
*/
32
32
class AccessLog extends ContentEntityBase implements AccessLogInterface {
33
33
34
+ /**
35
+ * Max length for Request URI field.
36
+ */
37
+ const REQUEST_URI_FIELD_MAX_LENGTH = 255 ;
38
+
34
39
/**
35
40
* {@inheritdoc}
36
41
*/
@@ -96,7 +101,10 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
96
101
->setLabel (t ('Request URI ' ))
97
102
->setDescription (t ('URI from which the request has been made. ' ))
98
103
->setRequired (TRUE )
99
- ->setReadOnly (TRUE );
104
+ ->setReadOnly (TRUE )
105
+ ->setSettings ([
106
+ 'max_length ' => self ::REQUEST_URI_FIELD_MAX_LENGTH ,
107
+ ]);
100
108
101
109
// Created field.
102
110
$ fields ['created ' ] = BaseFieldDefinition::create ('created ' )
Original file line number Diff line number Diff line change 3
3
namespace Drupal \os2web_logging \Logger ;
4
4
5
5
use Drupal \Core \Logger \RfcLoggerTrait ;
6
+ use Drupal \Core \StringTranslation \StringTranslationTrait ;
6
7
use Drupal \os2web_logging \Entity \AccessLog ;
7
8
use Psr \Log \LoggerInterface ;
8
9
11
12
*/
12
13
class AccessLogsDbLog implements LoggerInterface {
13
14
use RfcLoggerTrait;
15
+ use StringTranslationTrait;
14
16
15
17
/**
16
18
* {@inheritdoc}
17
19
*/
18
20
public function log ($ level , $ message , array $ context = []) {
21
+ if (strlen ($ context ['request_uri ' ]) > AccessLog::REQUEST_URI_FIELD_MAX_LENGTH ) {
22
+ $ request_uri = $ context ['request_uri ' ];
23
+ $ context ['request_uri ' ] = substr ($ request_uri , 0 , AccessLog::REQUEST_URI_FIELD_MAX_LENGTH );
24
+ $ message .= PHP_EOL ;
25
+ $ message .= $ this ->t ('Request URI has been truncated due to max_length restriction. ' ) . PHP_EOL ;
26
+ }
19
27
AccessLog::create ([
20
28
'sid ' => $ context ['sid ' ],
21
29
'uid ' => $ context ['uid ' ],
You can’t perform that action at this time.
0 commit comments