PHP Classes

File: test_log_watcher.php

Recommend this page to a friend!
  Classes of Manuel Lemos   Log watcher   test_log_watcher.php   Download  
File: test_log_watcher.php
Role: Example script
Content type: text/plain
Description: Example of how to setup the class to watch a given log file, e-mail the newly added lines, if any, and exit
Class: Log watcher
Watch a log file and e-mail newly added lines
Author: By
Last change: Added commented example settings on how to use the mail() function replacement function urgent_mail() for immediate delivery of new critical error log line entries.
Date: 20 years ago
Size: 1,938 bytes
 

Contents

Class file image Download
<?php
/*
 * test_log_watcher.php
 *
 * @(#) $Id: test_log_watcher.php,v 1.2 2004/07/27 08:05:58 mlemos Exp $
 *
 */

   
require('log_watcher_class.php');

   
$log_watcher=new log_watcher_class;

   
/*
     * Specify the file name of the log file to watch
     */
   
$log_watcher->log_file_name='/var/log/httpd/php_error_log';

   
/*
     * Specify who is going to receive the notifications about the new lines
     * added to the log file
     */
   
$log_watcher->watcher_name='Manuel Lemos';
   
$log_watcher->watcher_email='mlemos@acm.org';

   
/*
     * Specify who is going to be the sender of the notification messages
     */
   
$log_watcher->system_name='PHP log watcher';
   
$log_watcher->system_email='my@site.com';

   
/*
     * Often, error log entries are added due to critical bugs tha need to
     * fixed immediately. By default this class uses the PHP mail()
     * function to send the log file changes messages, but that may not be
     * the fastest way to deliver an urgent message as it is relayed to a
     * local mailer or an intermediate relay SMTP server.
     *
     * A convenient alternative is to use the urgent_mail function to
     * replace the mail function by uncommenting the following lines:
     *
     * require_once("email_message.php");
     * require_once("smtp_message.php");
     * require_once("smtp.php");
     * require_once("urgent_mail.php");
     *
     * $log_watcher->mail='urgent_mail';
     */

    /*
     * Open the log file and point it to the last line that was read or the
     * end of the file if this the first time the log is opened
     */
   
$log_watcher->OpenLog();

   
/*
     * Send the new log file lines, if any, in a message with the specified
     * subject
     */
   
$log_watcher->MailNews('PHP error log report');

   
/*
     * Close the log file and store the last line position in the pointer
     * file
     */
   
$success=$log_watcher->CloseLog();

   
/*
     * If there was an error, output it
     */
   
if(!$success)
        echo
'Log watcher error: ',$log_watcher->error,"\n";
?>