Created
June 3, 2020 11:15
-
-
Save glafarge/ed43e451c5a0eb1dc3a88904528575ce to your computer and use it in GitHub Desktop.
Finding specific messages from CakePHP 3.x logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$log = file_get_contents('./src/logs/error-test.log'); | |
// Find all logs messages matching a pattern to process them, filter them out... | |
$exceptions = ['RecordNotFoundException', 'MissingRouteException', 'MissingActionException', 'MissingControllerException']; | |
$words = implode($exceptions, '\b|'); | |
$re = '/^.*(\b'.$words.'\b)\][\s\S]+?(?=\n\n)/m'; | |
preg_match_all($re, $log, $matches, PREG_SET_ORDER, 0); | |
// All found entries in $matches | |
echo '<pre>'; | |
echo '=> Filtering-out ' . count($matches) . ' entries.'; | |
// and ...the rest | |
$rest = preg_replace($re, "", $log); | |
$rest = preg_replace('/^\s+/m', "\n\n", $rest); // removes multiple empty lines | |
echo $rest; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment