1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Ajde_Log extends Ajde_Object_Static |
4
|
|
|
{ |
5
|
|
|
const CHANNEL_EXCEPTION = 'Exception'; |
6
|
|
|
const CHANNEL_ERROR = 'Error'; |
7
|
|
|
const CHANNEL_ROUTING = 'Routing'; |
8
|
|
|
const CHANNEL_SECURITY = 'Security'; |
9
|
|
|
const CHANNEL_INFO = 'Info'; |
10
|
|
|
const CHANNEL_APPLICATION = 'Application'; |
11
|
|
|
|
12
|
|
|
const LEVEL_EMERGENCY = '1:Emergency'; |
13
|
|
|
const LEVEL_ALERT = '2:Alert'; |
14
|
|
|
const LEVEL_CRITICAL = '3:Critical'; |
15
|
|
|
const LEVEL_ERROR = '4:Error'; |
16
|
|
|
const LEVEL_WARNING = '5:Warning'; |
17
|
|
|
const LEVEL_NOTICE = '6:Notice'; |
18
|
|
|
const LEVEL_INFORMATIONAL = '7:Informational'; |
19
|
|
|
const LEVEL_DEBUG = '8:Debug'; |
20
|
|
|
|
21
|
|
|
private static function getWriters() |
22
|
|
|
{ |
23
|
|
|
$writerArray = config('security.log.writer'); |
24
|
|
|
$getWriters = []; |
25
|
|
|
foreach ($writerArray as $writer) { |
26
|
|
|
$getWriters[] = 'Ajde_Log_Writer_'.ucfirst($writer); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
return $getWriters; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
private static function shouldLog($level) |
33
|
|
|
{ |
34
|
|
|
$configLevel = current(explode(':', config('security.log.level'))); |
35
|
|
|
$logLevel = current(explode(':', $level)); |
36
|
|
|
|
37
|
|
|
return $configLevel >= $logLevel; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public static function _( |
41
|
|
|
$message, |
42
|
|
|
$channel = self::CHANNEL_INFO, |
43
|
|
|
$level = self::LEVEL_INFORMATIONAL, |
44
|
|
|
$description = '', |
45
|
|
|
$code = '', |
46
|
|
|
$trace = '' |
47
|
|
|
) { |
48
|
|
|
if (!self::shouldLog($level)) { |
49
|
|
|
return; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
foreach (self::getWriters() as $writer) { |
53
|
|
|
try { |
54
|
|
|
$result = @call_user_func_array($writer.'::_', |
55
|
|
|
[$message, $channel, $level, $description, $code, $trace]); |
56
|
|
|
if ($result) { |
57
|
|
|
break; |
58
|
|
|
} |
59
|
|
|
} catch (Exception $e) { |
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public static function d($message, $description = '') |
65
|
|
|
{ |
66
|
|
|
self::_($message, self::CHANNEL_INFO, self::LEVEL_INFORMATIONAL, $description); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public static function log($string) |
70
|
|
|
{ |
71
|
|
|
self::_($string); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|