Skip to content
Snippets Groups Projects
Commit 06a2e043 authored by mkoitka's avatar mkoitka Committed by Frank Naegler
Browse files

[TASK] Write cleaner FileWriter JSON output

Since PHP 5.4 it's possible to disable escaping for unicode characters
and slashes, which results in a much cleaner, leaner and most
importantly readable TYPO3 log output.

Releases: master, 9.5
Resolves: #88120
Related: #77274
Change-Id: I5b331e29e0f036d3d95b0f1045c269a28fec6abb
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60431


Reviewed-by: default avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: default avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: default avatarTomas Norre Mikkelsen <tomasnorre@gmail.com>
Reviewed-by: default avatarFrank Naegler <frank.naegler@typo3.org>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: default avatarFrank Naegler <frank.naegler@typo3.org>
parent 92b06614
Branches
Tags
No related merge requests found
......@@ -154,7 +154,7 @@ class FileWriter extends AbstractWriter
if (isset($recordData['exception']) && $recordData['exception'] instanceof \Exception) {
$recordData['exception'] = (string)$recordData['exception'];
}
$data = '- ' . json_encode($recordData);
$data = '- ' . json_encode($recordData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
$message = sprintf(
......
......@@ -152,6 +152,28 @@ class FileWriterTest extends UnitTestCase
$this->assertEquals($expectedResult, $logFileContents);
}
/**
* @test
*/
public function logsToFileWithUnescapedCharacters(): void
{
$this->setUpVfsStream();
$recordWithData = GeneralUtility::makeInstance(
LogRecord::class,
$this->getUniqueId('test.core.log.fileWriter.recordWithData.'),
\TYPO3\CMS\Core\Log\LogLevel::INFO,
'test record with unicode and slash in data to encode',
['foo' => ['bar' => 'I paid 0.00€ for open source projects/code']]
);
$expectedResult = '{"foo":{"bar":"I paid 0.00€ for open source projects/code"}}';
$this->createWriter('encoded-data')->writeLog($recordWithData);
$logFileContents = trim(file_get_contents($this->getDefaultFileName('encoded-data')));
$this->assertContains($expectedResult, $logFileContents);
}
/**
* @test
* @param LogRecord $record Record Test Data
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment