Bug Happens...

Every developer knows that. The nasty thing is that if you want to see what happened, you have to crawl between hundred lines log files, written in txt format, with no options to see them in an easier format, perhaps grouped by time.





That's why LogHappens exists!

LogHappens aims to fix this lack. It is a simple tool, it will not make your software magically bug-free, but it will notify you immediately when something has been logged by your web server or your favorite framework.

Does it handle different log formats?

Of course it does. While it is true that every software has its own bugs, every software have its own way of logging things too. This is why I have tried to make it as simple as possible to let you create your own routine for reading log files. No fancy regex strings: if you just want to read the file, you can group log entries by date/time and print the rest of the file. If you are feeling adventurous, you can possibly do whatever you want: highlight words, create tags, split errors... the only limit is your fantasy.

Stil not convinced? See the "parsers" section to see an example of a log parser.

What does it look like?

It looks like this:

A screenshot of the LogHappens interface

Did I mention it's free?

Because it is. Free and Open Source. I'm enjoying a lot of Open Source Software, that's why I've decided to give something back.

How does a parser work?

It's essentially quite simple. Take a look at the following examples to have a glance on how it works.

If you need to view logs for another framework, those examples could be a good "hello world" code too :)

Apache 2.4

<?php
$menu = [
    'icon' => 'build',
    'color' => 'red',
    'title' => 'Apache error.log',
    'file' => '/var/log/apache2/error.log'
];

$content = file($menu['file']);

$log = [];
foreach ($content as $line) {
    // Grab the log's time and group logs by time
    $time = substr($line, 1, 19);
    $time = date("l d-m-Y - H:i:s", strtotime($time));

    // Remove date-time and other useless informations from the log details
    $line = substr($line, 34);
    $line = preg_replace('[\[:error.*\]]', '', $line);
    $line = preg_replace('[\[pid .*\]]', '', $line);
    $line = str_replace('PHP', '', $line);
    $line = trim($line);

    // Highlight the type of errors, using a badge
    $line = preg_replace("/^Notice: /", "<span class='lh-badge' style='background-color: #318418;'>Notice:</span> ", $line);
    $line = preg_replace("/^Warning: /", "<span class='lh-badge' style='background-color: #a79716;'>Warning:</span> ", $line);
    $line = preg_replace("/^Fatal error: /", "<span class='lh-badge' style='background-color: #a71616;'>Fatal error:</span> ", $line);
    $line = preg_replace("/^Parse error: /", "<span class='lh-badge' style='background-color: #a71616;'>Parse error:</span> ", $line);
    $line = preg_replace("/^Error: /", "<span class='lh-badge' style='background-color: #a71616;'>Error:</span> ", $line);

    // Save the log entry
    $log[$time][] = $line;
}

// Reverse the logs, so that we can see last errors first
$logs = array_reverse($log);

CakePHP 3.x

<?php
            $menu = [
                "icon" => "send",
                "color" => "teal",
                "title" => "My CakePHP App error.log",
                "file" => "/var/www/mycakeapp/logs/error.log"
            ];

            $content = file($menu['file']);

            $log = [];
            foreach ($content as $line) {
                // Don't print the datetime for every record
                if (substr($line, 0, 3) == "201") {
                    $time = substr($line, 0, 20);
                    $line = str_replace($time, "", $line);
                }
                $time = date("l d-m-Y - H:i:s", strtotime($time));
                $line = trim($line);

                // Highlight the type of errors, using a badge
                $line = preg_replace("/^Notice: /", "<span class='lh-badge' style='background-color: #318418;'>Notice:</span> ", $line);
                $line = preg_replace("/^Warning: /", "<span class='lh-badge' style='background-color: #a79716;'>Warning:</span> ", $line);
                $line = preg_replace("/^Fatal error: /", "<span class='lh-badge' style='background-color: #a71616;'>Fatal error:</span> ", $line);
                $line = preg_replace("/^Parse error: /", "<span class='lh-badge' style='background-color: #a71616;'>Parse error:</span> ", $line);
                $line = preg_replace("/^Error: /", "<span class='lh-badge' style='background-color: #a71616;'>Error:</span> ", $line);

                // Save the log entry
                $log[$time][] = $line;
            }

            // Reverse the logs, so that we can see last errors first
            $logs = array_reverse($log);
            

Download & Installation

To install LogHappens, please follow these steps:

  • Get LogHappens (choose your favourite method):
  • Place LogHappens in a folder executable by apache or ngnix
  • Using the files in `logic_templates`, create create a new template in the `logics` folder
  • Open the browser to the destination you have installed LogHappens
  • Enjoy!
Need support? Please accept cookies and refresh the page :-)