Skip to content

Instantly share code, notes, and snippets.

@nickvergessen
Created June 6, 2016 12:05
Show Gist options
  • Select an option

  • Save nickvergessen/3bc6c0c7ada1a3c4a1b1f5ed94cc61f6 to your computer and use it in GitHub Desktop.

Select an option

Save nickvergessen/3bc6c0c7ada1a3c4a1b1f5ed94cc61f6 to your computer and use it in GitHub Desktop.
<?php
/**
* The MIT License (MIT)
*
* Copyright (c) 2014 nickvergessen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
$log = <<<'EOT'
{ INSERT LOG HERE }
EOT;
$log = json_decode(trim($log), true, 4024);
if (substr($log['message'], 0, 11) === 'Exception: ') {
$message = substr($log['message'], 11);
$exception = json_decode($message, true);
if ($exception === null) {
$message = str_replace("\\", '\\\\', $message);
}
$exception = json_decode($message, true);
if (isset($exception['Trace'])) {
$exception['Trace'] = explode("\n", $exception['Trace']);
$traces = [];
foreach ($exception['Trace'] as $trace) {
if (substr_count($trace, ' ') == 2) {
list($index, $file, $code) = explode(' ', $trace, 3);
} else {
list($index, $file) = explode(' ', $trace, 2);
$code = null;
}
$traces[$index] = [$file, $code];
}
$exception['Trace'] = $traces;
}
$log['message'] = array('Exception' => $exception);
} else if (substr($log['message'], 0, 10) === 'backtrace#') {
$message = substr($log['message'], 10);
#$message = str_replace("\\", '\\\\', $message);
$exception = unserialize($message);
if (isset($exception['Trace'])) {
$exception['Trace'] = explode('\n', $exception['Trace']);
$traces = [];
foreach ($exception['Trace'] as $trace) {
list($index, $file, $code) = explode(' ', $trace, 3);
$traces[$index] = [$file, $code];
}
$exception['Trace'] = $traces;
}
$log['message'] = array('Exception' => $exception);
}
$output = json_encode($log, JSON_PRETTY_PRINT);
$output = str_replace(['\\\\\\/', '\\/', '\\\\'], ['/', '/', '\\'], $output);
echo str_replace(["\n", '\n', ' '], ['<br />', '<br />', '&nbsp;&nbsp;&nbsp;&nbsp;'], $output);//json_encode($log['message'], JSON_PRETTY_PRINT) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment