-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.class.php
More file actions
71 lines (63 loc) · 1.16 KB
/
handler.class.php
File metadata and controls
71 lines (63 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Log Handler Base Class
*/
class NyaaLogHandler
{
protected $template;
/**
* Constructer
*
* @params NyaaLog
*/
public function __construct( $Log )
{
$this->log = $Log;
$this->template = $Log->get('template');
}
/**
* Factory
*
* @param name
* @param Log
*/
public function factory( $name, $Log )
{
$file = dirname(__FILE__).'/handler.'.$name.'.class.php';
if( !file_exists( $file ) )
trigger_error("Handler $name is not exists",E_USER_WARNING);
require_once $file;
$class = 'NyaaLogHandler'.ucfirst($name);
if( !class_exists( $class ) )
trigger_error("Handler $class is not exists",E_USER_WARNING);
return new $class( $Log );
}
/**
* Create Log Message
*
* @params int $lv, string $log
*/
public function getMessage( $lv, $string )
{
$string = preg_replace(
'/%([a-z]+)/e',
'$this->log->getLogParts("\1",$lv, $string);',
$this->template
);
return $string;
}
public function setTemplate( $tpl )
{
$this->template = $tpl;
}
/**
* Execute Process
*
* @params int $lv, string $log
*/
public function process( $lv, $string )
{
echo $this->getMessage( $lv, $string );
}
}
?>