More on presentation of logs ...

Discussion in 'General' started by mike_p, Feb 17, 2011.

  1. mike_p

    mike_p New Member

    1/ Formatting logs.

    I think we can improve on the 'raw' display of logs, so I've been experimenting with better formatting.

    I've written a simple function to go in the show_log.php script that converts the data into an html table:

    Code:
    function log_to_table($datastring) {
      $data_lines = explode("\n", $datastring);
      $html = "<table class='log_table'>";
      foreach ($data_lines as $value) {
        $items = explode(' ',$value,6);
        $html .= "<tr>";
        $html .= "<td>$items[0] $items[1]</td>"; //date
        $html .= "<td>$items[2]</td>"; //time
        $html .= "<td>$items[3]</td>"; //server
        $html .= "<td>$items[4]</td>"; //user
        $html .= "<td>$items[5]</td>"; //data
        $html .= "<tr>";
        }
      $html .= "</table>";
      return $html;
      };
    
    then I replace the nl2br function with log_to_table.

    After that we need a little tidying up with the css. In my test I use:

    Code:
    table.log_table td {
         font-family: Trebuchet MS;
         font-size:8pt;
         border-width: 1px;
         padding: 1px 3px;
         border-style: solid;
         border-color: #ded;
         min-width:4em;
         }
    Conceptually I'm not sure where it should be placed. In my case I've added it to the end of content.css.

    2/ In Redhat[Centos] and Gentoo distributions the maillog, mail error and mail warning logs all show the content of maillog.

    I propose we split the logs.

    1. Edit /etc/syslog.conf replace
    Code:
    # Log all the mail messages in one place.
    mail.*                                                  -/var/log/maillog
    with
    Code:
    mail.info;mail.!warn    /var/log/maillog
    mail.warn;mail.!err     /var/log/mail.warn
    mail.err        /var/log/mail.err
    then restart syslog with /etc/init.d/syslog restart

    2/ Adjust ISPConfig to use the new error and warning logs:
    Edit monitor_core_module.inc.php around line 1666 change


    Code:
    case 'log_mail_warn':
    	if($dist == 'debian') { $logfile = '/var/log/mail.warn'; }
    	elseif($dist == 'redhat') { $logfile = '/var/log/maillog'; }
    	elseif($dist == 'suse') { $logfile = '/var/log/mail.warn'; }
    	elseif($dist == 'gentoo') { $logfile = '/var/log/maillog'; }
    	break;
    case 'log_mail_err':
            if($dist == 'debian') { $logfile = '/var/log/mail.err'; }
            elseif($dist == 'redhat') { $logfile = '/var/log/maillog'; }
            elseif($dist == 'suse') { $logfile = '/var/log/mail.err'; }
    	elseif($dist == 'gentoo') { $logfile = '/var/log/maillog'; }
    	break;
    to
    Code:
    case 'log_mail_warn':
    	$logfile = '/var/log/mail.warn'; 
    	break;
    case 'log_mail_err':
            $logfile = '/var/log/mail.err'; 
    	break;
    I've tested in Centos, can't be sure of Gentoo.

    Might also need to have a play with "logrotate".

    Anyone interested in this being incorporated into the next release?
     
    Last edited: Feb 17, 2011
  2. mike_p

    mike_p New Member

    Time to revisit this!

    I've just had to troubleshoot some mail problems and found the standard mail log presentation very poor. Having updated ISPConfig since my last look at mail problems, my changes had been lost.

    I'm running on Centos, so for some strange reason ISPConfig decides to use/show the main maillog for warnings and errors.

    Almost worse, because it shows the logs without replacing HTML entitities, the display of email addresses in the logs gets mangled.
    example: some mail log messages show email addresses as
    <john@example.com>
    because of the bracketing ('<'..'>') webbrowsers will assume an unknown html tag and not show the content.

    So as in the first post in this thread (with one small change) I recommend adding this to show_log.php
    Code:
    function log_to_table($datastring) {
      $data_lines = explode("\n", $datastring);
      $html = "<table class='log_table'>";
      foreach ($data_lines as $value) {
        $items = explode(' ',htmlentities($value),6);
        $html .= "<tr>";
        $html .= "<td>$items[0] $items[1]</td>"; //date
        $html .= "<td>$items[2]</td>"; //time
        $html .= "<td>$items[3]</td>"; //server
        $html .= "<td>$items[4]</td>"; //user
        $html .= "<td>$items[5]</td>"; //data
        $html .= "<tr>";
        }
      $html .= "</table>";
      return $html;
      };
    
    Then replace
    Code:
    $logData = nl2br($data);
    
    with
    Code:
    $logData = log_to_table($data);
    
    then follow the instructions for adding to the css
    ----------------------------
    The second change was to ensure that the warnings and logs are in separate logs. /the instructions remainthe same as my original post except the changes to monitor_core_module.inc.php should now be made to monitor_tools.inc.php instead.
     
    Last edited: Jan 25, 2012

Share This Page