<?php
/*
* 日志类文件
* 日志记录等级 分为三级 错误日志(error) 调试日志(debug) 跟踪日志(trace) 根据需要选择
*/
class klog {
static $path = 'D:\log'; //定义log日志文件的存放路径
//static $level = 3;
static function init($timezone, $loglevel = 2 ) {
date_default_timezone_set( $timezone );
//klog::$path = $path;
//klog::$level = $loglevel;
umask(0);
}
static function logging( $string ) {
$file = klog::$path . '/' . date("Ymd") . '.log';
$id = defined( 'SESS_ID') ? SESS_ID : '';
$email = isset( $_SESSION['email'] ) ? $_SESSION['email'] : '';
@error_log(
date("[Y-m-d H:i:s]") . " [" . $sid . "] [" . $email . "] [" . $_SERVER['REMOTE_ADDR'] . "] [".$_SERVER['REQUEST_URI']. "] " . $string . "\r\n",
3,
$file
);
}
var $func = '';
//初始化数据
function __construct( $func = 'global' ) {
$this->func = $func;
$this->debug( "begin ~~~" );
}
function __destruct( ) {
$this->debug( "end ..." );
}
function try_covert_to_string( &$input ) {
if( is_object( $input ) || is_array( $input ) ) {
$input = var_export( $input, true );
}
}
//错误日志
function error( $string ) {
//if( klog::$level < 1 ) return;
$this->try_covert_to_string( $string );
klog::logging( "error [" . $this->func . "] " . $string );
}
//跟踪日志
function trace( $string ) {
//if( klog::$level < 2 ) return;
$this->try_covert_to_string( $string );
klog::logging( "trace [" . $this->func . "] " . $string );
}
//调试日志
function debug( $string ) {
//if( klog::$level < 3 ) return;
$this->try_covert_to_string( $string );
klog::logging( "debug [" . $this->func . "] " . $string );
}
}
?>
看注释差不多就行了 没什么好说的了
一个个人觉得比较好用的PHP日志类,给大家分享一下
最新推荐文章于 2024-03-11 17:23:15 发布