Completed
Push — feature/0.7.0 ( 9b3495...0c7d59 )
by Ryuichi
43:39
created

LoggerUtils::addStackTrace()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 2
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace WebStream\Log;
3
4
use WebStream\Exception\Extend\LoggerException;
5
6
/**
7
 * LoggerUtils
8
 * @author Ryuichi Tanaka
9
 * @since 2015/12/26
10
 * @version 0.7
11
 */
12
trait LoggerUtils
13
{
14
    /**
15
     * デフォルトロガーフォーマッタ
16
     * @return string デフォルトロガーフォーマッタ
17
     */
18
    public function defaultLoggerFormatter()
19
    {
20
        return '[%d{' . $this->defaultDateTimeFormatter() . '.%f}][%5L] %m';
21
    }
22
23
    /**
24
     * デフォルトDateTimeフォーマッタ
25
     * @return string デフォルトDateTimeフォーマッタ
26
     */
27
    public function defaultDateTimeFormatter()
28
    {
29
        return "%Y-%m-%d %H:%M:%S";
30
    }
31
32
    /**
33
     * ログレベルを数値に変換
34
     * ログレベルはWebStream独自、PSR-3両方対応
35
     * @param string ログレベル文字列
36
     * @throws LoggerException
37
     * @return int ログレベル数値
38
     */
39
    public function toLogLevelValue(string $level)
40
    {
41
        switch (strtolower($level)) {
42
            case 'debug':
43
                return 1;
44
            case 'info':
45
                return 2;
46
            case 'notice':    // PSR-3
47
                return 3;
48
            case 'warn':
49
            case 'warning':   // PSR-3
50
                return 4;
51
            case 'error':
52
                return 5;
53
            case 'critical':  // PSR-3
54
                return 6;
55
            case 'alert':     // PSR-3
56
                return 7;
57
            case 'emergency': // PSR-3
58
                return 8;
59
            case 'fatal':
60
                return 9;
61
            default:
62
                throw new LoggerException("Undefined log level: $level");
63
        }
64
    }
65
}
66