I'm having a little issue with regexp, i know this isn't directly a magento issue though.
My goal is to get a sub printing of magento logs in the admin.
To do so, I've created the following method
public function getLog($logfile,$nbLine = null){
$nbCharPerLineApproximative = 100;
$nbLine = $nbLine == null?$this->getNbLineToPrint():$nbLine;
$contents = null;
try {
$path = $this->directoryList->getPath('var').'/log/'.$logfile ;
$fileSubContent = substr($this->driverFile->fileGetContents($path),- $nbLine * $nbCharPerLineApproximative);
var_dump($fileSubContent);
$re = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}][[:print:]]{1,}/';
preg_match_all($re, $fileSubContent, $contents, PREG_SET_ORDER, 0);
var_dump($contents);
} catch (FileSystemException $e) {
var_dump($e->getMessage());
}
return $contents;
}
$fileSubContent, will get all the data perfectly. But the regex is messing with accent.
As an exemple the regexp will match
Paypal a rejete le paiement.
But it will only match
Paypal a rejet
if the real sentence is
Paypal a rejeté le paiement.
The main goal being to retrieve all data "logs by logs" and not just line by line
[2021-08-10 12:21:14] main.ERROR: Unable to unserialize value. [] [] [2021-08-10 12:25:45] main.ERROR: Paypal a rejeté la demande. [] []