Skip to content

Instantly share code, notes, and snippets.

@glafarge
Created June 3, 2020 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glafarge/ed43e451c5a0eb1dc3a88904528575ce to your computer and use it in GitHub Desktop.
Save glafarge/ed43e451c5a0eb1dc3a88904528575ce to your computer and use it in GitHub Desktop.
Finding specific messages from CakePHP 3.x logs
<?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