<?php
//
// +----------------------------------------------------------------------+
// | <Log4P/> version 1.0 |
// +----------------------------------------------------------------------+
// | The contents of this file are subject to the Mozilla Public License |
// | Version 1.1 (the "License"); you may not use this file except in |
// | compliance with the License. You may obtain a copy of the License at |
// | http://www.mozilla.org/MPL/ |
// | |
// | Software distributed under the License is distributed on an "AS IS" |
// | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
// | the License for the specific language governing rights and |
// | limitations under the License. |
// | |
// | The Original Code is <Log4P/>. |
// | |
// | The Initial Developer of the Original Code is Kevin Lee(R.P.China). |
// | Portions created by Kevin Lee are Copyright (C) 2001 Kevin Lee. |
// | All Rights Reserved. |
// +----------------------------------------------------------------------+
// | Authors: |
// | Kevin Lee <hide@address.com> |
// +----------------------------------------------------------------------+
// $Id: Logger.php,v 1.1 2003/07/06 07:24:08 rui.li Exp $
//
/**
* ÓÃÀ´¼Ç¼ÈÕÖ¾µÄÀà
Ïë·¨£º
ÔÚ³õʼ»¯Ê±£¬Ö¸Ã÷log¼Ç¼·¾¶
·ÖÁ½ÖÖ·½Ê½½øÐмǼ
ÈÕÆÚÐÍ(date)£ºÎļþÃûΪµ±Ç°ÈÕÆÚ(È磺/websit/d6web/logs/login/20030805.log)
¸ñʽΪ£ºÃ¿Ò»¸ö¶¯×÷Ò»ÐмǼ£¬Ã¿ÐпªÍ·Îªµ±Ç°Ê±¼ä£¬ÈçÏÂ
[Fri May 09 12:49:26 2003] [error] [client 61.232.0.20] File does not exist: /websit/shiyan/bbs/$imgdir
*/
Class Logger
{
$LogPath = _LOG_PATH;
function Logger( $LogName )
{
$this->file_name = $LogPath."/".$LogName."/".date("Ymd").".log";
// $this->load_file();
}
function test()
{
return $this->file_name;
}
function LogWriter()
{
echo "[".date("D M d H:i:s Y")."]";
}
function load_file($file)
{
if( $fp=fopen($file ,"a") ){
$this->fp = $fp;
}
else
$this->display_error("File %s could not be found or read.", $file);
}
/**
* Displays an error message.
*
* This method displays an error messages and stops the execution of the
* script. This method is called exactly in the same way as the printf
* function. The first argument contains the message and additional
* arguments of various types may be passed to this method to be inserted
* into the message.
*
* @access private
* @author Michael P. Mehl <hide@address.com>
* @param string $message Error message to be displayed.
*/
function display_error ( $message )
{
// Check whether more than one argument was given.
if ( func_num_args() > 1 ){
// Read all arguments.
$arguments = func_get_args();
// Create a new string for the inserting command.
$command = "\$message = sprintf(\$message, ";
// Run through the array of arguments.
for ( $i = 1; $i < sizeof($arguments); $i++ ){
// Add the number of the argument to the command.
$command .= "\$arguments[".$i."], ";
}
// Replace the last separator.
$command = eregi_replace(", $", ");", $command);
// Execute the command.
eval($command);
}
// Display the error message.
echo "<b>Log4P error:</b> ".$message;
// End the execution of this script.
exit;
}
}
?>