First commit
This commit is contained in:
125
weixinpay/example/log.php
Executable file
125
weixinpay/example/log.php
Executable file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
//以下为日志
|
||||
|
||||
|
||||
|
||||
interface ILogHandler
|
||||
|
||||
{
|
||||
|
||||
public function write($msg);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class CLogFileHandler implements ILogHandler
|
||||
|
||||
{
|
||||
|
||||
private $handle = null;
|
||||
|
||||
|
||||
|
||||
public function __construct($file = '')
|
||||
|
||||
{
|
||||
|
||||
$this->handle = fopen($file,'a');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function write($msg)
|
||||
|
||||
{
|
||||
|
||||
fwrite($this->handle, $msg, 4096);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function __destruct()
|
||||
|
||||
{
|
||||
|
||||
fclose($this->handle);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Log
|
||||
|
||||
{
|
||||
|
||||
private $handler = null;
|
||||
|
||||
private $level = 15;
|
||||
|
||||
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
|
||||
|
||||
private function __construct(){}
|
||||
|
||||
|
||||
|
||||
private function __clone(){}
|
||||
|
||||
|
||||
|
||||
public static function Init($handler = null,$level = 15)
|
||||
|
||||
{
|
||||
|
||||
if(!self::$instance instanceof self)
|
||||
|
||||
{
|
||||
|
||||
self::$instance = new self();
|
||||
|
||||
self::$instance->__setHandle($handler);
|
||||
|
||||
self::$instance->__setLevel($level);
|
||||
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private function __setHandle($handler){
|
||||
|
||||
$this->handler = $handler;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function __setLevel($level)
|
||||
|
||||
{
|
||||
|
||||
$this->level = $level;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function DEBUG($msg)
|
||||
|
||||
{
|
||||
Reference in New Issue
Block a user