Issues (37)

LoggerUtils.php (1 issue)

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