How can I have a list of exceptions from a exception.log file ?

Sometime this files are very big and the only way to analyze them is using Vim or similar cli tools. I would like php approach (so platform independent)


This is no answer, but maybe it helps.

I think for the future you should think about a solution like logstash, Graylog2 or Loggly to collect, aggregate and analyze the exceptions.

This all can be done with FireGento_Logger. I'm still NOT using it, but heard a lot of great things about it, because you can see immediately on which server what happens or which errors are raising on different servers again and again.

  • are you sure about this: which errors are raising on different servers again ... it looks a single store extension ... – Fra May 30 '14 at 15:58
  • 1
    FireGento_Logger is installed in one store, but logstash, Graylog and loggly are logging server, which collect the errors from all the instances you install the logger on. – Fabian Blechschmidt May 30 '14 at 15:59

Following code is an example ( very raw ) for a possible approach to fast collect/extract info from a big log file.

It will:

  • try to group/count the exception messages
  • list all exception ordered by count.

I hope it helps, I tested it on +200MB log and it is enough fast.


function parseReport()
    $exceptions = array();
    if (isset($_GET["submit"])) {
        $fileName = $_GET['filepath'];
        $handle = @fopen($fileName, "r");

        if ($handle) {
            $isNewEx = true;
            // Collect Exception
            while (($buffer = fgets($handle, 4096)) !== false) {
                $arr = explode(' ', trim($buffer));
                if (strpos($arr[0], 'exception') !== false) {
                    //exception start
                    $isNewEx = true;
                    foreach ($exceptions as $k => $ex) {
                        if ($ex[0] == $buffer) {
                            $exceptions[$k][1] += 1;
                            $isNewEx = false;
                    if ($isNewEx) {
                        $exceptions[] = array($buffer, 1);
            if (!feof($handle)) {
                echo "Error: unexpected fgets() fail\n";
    return $exceptions;


<!DOCTYPE html>
    .exception_row {
        border: 1px solid #000000;
        padding: 2px;

<form action="readBigExceptionLog.php" method="get" enctype="multipart/form-data">
    Local File Path:
    <input type="input" name="filepath" id="filepath">
    <input type="submit" value="Process" name="submit">
<?php foreach (parseReport() as $i => $ex): ?>
    <div class="exception_row">
        <?php echo "[{$i}] (Count:{$ex[1]}) - $ex[0]"; ?>
<?php endforeach; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.