-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoggerUtils.php
66 lines (61 loc) · 1.64 KB
/
LoggerUtils.php
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
<?php
namespace WebStream\Log;
use WebStream\Exception\Extend\LoggerException;
/**
* LoggerUtils
* @author Ryuichi Tanaka
* @since 2015/12/26
* @version 0.7
*/
trait LoggerUtils
{
/**
* デフォルトロガーフォーマッタ
* @return string デフォルトロガーフォーマッタ
*/
public function defaultLoggerFormatter()
{
return '[%d{' . $this->defaultDateTimeFormatter() . '.%f}][%5L] %m';
}
/**
* デフォルトDateTimeフォーマッタ
* @return string デフォルトDateTimeフォーマッタ
*/
public function defaultDateTimeFormatter()
{
return "%Y-%m-%d %H:%M:%S";
}
/**
* ログレベルを数値に変換
* ログレベルはWebStream独自、PSR-3両方対応
* @param string ログレベル文字列
* @throws LoggerException
* @return int ログレベル数値
*/
public function toLogLevelValue(string $level)
{
switch (strtolower($level)) {
case 'debug':
return 1;
case 'info':
return 2;
case 'notice': // PSR-3
return 3;
case 'warn':
case 'warning': // PSR-3
return 4;
case 'error':
return 5;
case 'critical': // PSR-3
return 6;
case 'alert': // PSR-3
return 7;
case 'emergency': // PSR-3
return 8;
case 'fatal':
return 9;
default:
throw new LoggerException("Undefined log level: $level");
}
}
}