Example #1
0
/**
 * Get last X lines of log file, with html tags to provide highlighting
 */
function logfiles_get_logfile($lines = 500, $file)
{
    global $amp_conf;
    $files = logfiles_list();
    $logfile = $amp_conf['ASTLOGDIR'] . '/' . $files[$file];
    if (!file_exists($logfile) || !is_file($logfile)) {
        echo _('Error parsing log file or file not found!');
        return;
    }
    $channels = array();
    exec(fpbx_which('tail') . ' -n' . $lines . ' ' . $logfile, $log);
    foreach ($log as $l) {
        switch (true) {
            case strpos($l, 'INFO'):
                $l = '<span class="beige">' . htmlentities($l) . '</span>';
                break;
            case strpos($l, 'WARNING'):
                $l = '<span class="orange">' . htmlentities($l) . '</span>';
                break;
            case strpos($l, 'DEBUG'):
                $l = '<span class="green">' . htmlentities($l) . '</span>';
                break;
            case strpos($l, 'UPDATE'):
            case strpos($l, 'NOTICE'):
                $l = '<span class="cyan">' . htmlentities($l) . '</span>';
                break;
            case strpos($l, 'FATAL'):
            case strpos($l, 'CRITICAL'):
            case strpos($l, 'ERROR'):
                $l = '<span class="red">' . htmlentities($l) . '</span>';
                break;
            default:
                $l = logfiles_highlight_asterisk(htmlentities($l, ENT_NOQUOTES), $channels);
                break;
        }
        echo $l . '<br />';
    }
}
/**
 * Get last X lines of log file, with html tags to provide highlighting
 */
function logfiles_get_logfile($lines = 500, $file, $filter = false)
{
    global $amp_conf;
    $files = logfiles_list();
    $logfile = $amp_conf['ASTLOGDIR'] . '/' . $files[$file];
    if (!file_exists($logfile) || !is_file($logfile)) {
        echo _('Error parsing log file or file not found!');
        return;
    }
    $channels = array();
    exec(fpbx_which('tail') . ' -n' . $lines . ' ' . $logfile, $log);
    if ($filter) {
        $regex_check = @preg_match('/' . $filter . '/', null);
        if ($regex_check !== 0) {
            echo _("Invalid pattern");
            return;
        } else {
            $log = preg_grep('/' . $filter . '/', $log);
        }
    }
    //If we filter out all the things....
    if (empty($log)) {
        echo _("No lines returned");
        return;
    }
    foreach ($log as $l) {
        switch (true) {
            case strpos($l, 'INFO'):
                $l = '<span class="beige">' . htmlentities($l, ENT_COMPAT | ENT_HTML401, "UTF-8") . '</span>';
                break;
            case strpos($l, 'WARNING'):
                $l = '<span class="orange">' . htmlentities($l, ENT_COMPAT | ENT_HTML401, "UTF-8") . '</span>';
                break;
            case strpos($l, 'DEBUG'):
                $l = '<span class="green">' . htmlentities($l, ENT_COMPAT | ENT_HTML401, "UTF-8") . '</span>';
                break;
            case strpos($l, 'UPDATE'):
            case strpos($l, 'NOTICE'):
                $l = '<span class="cyan">' . htmlentities($l, ENT_COMPAT | ENT_HTML401, "UTF-8") . '</span>';
                break;
            case strpos($l, 'FATAL'):
            case strpos($l, 'CRITICAL'):
            case strpos($l, 'ERROR'):
                $l = '<span class="red">' . htmlentities($l, ENT_COMPAT | ENT_HTML401, "UTF-8") . '</span>';
                break;
            default:
                $l = logfiles_highlight_asterisk(htmlentities($l, ENT_NOQUOTES, "UTF-8"), $channels);
                break;
        }
        echo $l . '<br />';
    }
}