Skip to content

Commit 3e2b34b

Browse files
authored
Check for large entries. (#52)
* Check for large entries. * Check for large entries.
1 parent 5dbe186 commit 3e2b34b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Model/Table/DatabaseLogsTable.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,20 @@ public function searchManager() {
100100
public function log($level, $message, array $context = []) {
101101
$message = trim($message);
102102
$summary = Text::truncate($message, 255);
103+
$context = trim(print_r($context, true));
104+
105+
if (mb_strlen($message) > 65535) {
106+
$message = mb_substr($message, 0, 65535);
107+
}
108+
if (mb_strlen($context) > 65535) {
109+
$context = mb_substr($context, 0, 65535);
110+
}
103111

104112
$data = [
105113
'type' => $level,
106114
'summary' => $summary,
107115
'message' => $message,
108-
'context' => trim(print_r($context, true)),
116+
'context' => $context,
109117
'count' => 1,
110118
];
111119
$log = $this->newEntity($data);

tests/TestCase/Model/Table/DatabaseLogsTableTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,28 @@ public function testSave() {
6262
$this->assertTrue($log->isCli());
6363
}
6464

65+
/**
66+
* @return void
67+
*/
68+
public function testSaveHugeText() {
69+
$string = $this->string(66000);
70+
$result = $this->Logs->log(LOG_INFO, $string, [$string]);
71+
$this->assertTrue($result);
72+
}
73+
74+
/**
75+
* @param int $length
76+
* @return string
77+
*/
78+
protected function string(int $length): string {
79+
$string = '';
80+
for ($i = 0; $i < $length; $i++) {
81+
$string .= 'X';
82+
}
83+
84+
return $string;
85+
}
86+
6587
/**
6688
* @return void
6789
*/

0 commit comments

Comments
 (0)