1 | <?php |
||
22 | class AnsiFormatter extends DefaultFormatter |
||
23 | { |
||
24 | /** |
||
25 | * foreground color |
||
26 | * |
||
27 | * @const |
||
28 | */ |
||
29 | const FGCOLOR_BLACK = "\033[0;30m"; |
||
30 | const FGCOLOR_RED = "\033[0;31m"; |
||
31 | const FGCOLOR_GREEN = "\033[0;32m"; |
||
32 | const FGCOLOR_YELLOW = "\033[0;33m"; |
||
33 | const FGCOLOR_BLUE = "\033[0;34m"; |
||
34 | const FGCOLOR_MAGENTA = "\033[0;35m"; |
||
35 | const FGCOLOR_CYAN = "\033[0;36m"; |
||
36 | const FGCOLOR_GRAY = "\033[0;37m"; |
||
37 | const FGCOLOR_DARK_GRAY = "\033[1;30m"; |
||
38 | const FGCOLOR_BRIGHT_RED = "\033[1;31m"; |
||
39 | const FGCOLOR_BRIGHT_GREEN = "\033[1;32m"; |
||
40 | const FGCOLOR_BRIGHT_YELLOW = "\033[1;33m"; |
||
41 | const FGCOLOR_BRIGHT_BLUE = "\033[1;34m"; |
||
42 | const FGCOLOR_BRIGHT_MAGENTA = "\033[1;35m"; |
||
43 | const FGCOLOR_BRIGHT_CYAN = "\033[1;36m"; |
||
44 | const FGCOLOR_WHITE = "\033[1;37m"; |
||
45 | /** |
||
46 | * background color |
||
47 | * |
||
48 | * @const |
||
49 | */ |
||
50 | const BGCOLOR_BLACK = "\033[40m"; |
||
51 | const BGCOLOR_RED = "\033[41m"; |
||
52 | const BGCOLOR_GREEN = "\033[42m"; |
||
53 | const BGCOLOR_YELLOW = "\033[43m"; |
||
54 | const BGCOLOR_BLUE = "\033[44m"; |
||
55 | const BGCOLOR_MAGENTA = "\033[45m"; |
||
56 | const BGCOLOR_CYAN = "\033[46m"; |
||
57 | const BGCOLOR_WHITE = "\033[47m"; |
||
58 | const DECO_BOLD = "\033[1m"; |
||
59 | const DECO_UNDERLINE = "\033[4m"; |
||
60 | const DECO_BLINK = "\033[5m"; |
||
61 | const DECO_REVERSE = "\033[7m"; |
||
62 | const DECO_CROSS = "\033[9m"; |
||
63 | const DECO_END = "\033[0m"; |
||
64 | |||
65 | /** |
||
66 | * Color definitions for different log levels |
||
67 | * format [ fgColor, bgColor, textDeco ] |
||
68 | * |
||
69 | * @var array |
||
70 | * @access protected |
||
71 | */ |
||
72 | protected $colors = array( |
||
73 | LogLevel::DEBUG => [self::FGCOLOR_GRAY, '', ''], |
||
74 | LogLevel::INFO => ['', '', ''], |
||
75 | LogLevel::NOTICE => [self::FGCOLOR_BRIGHT_GREEN, '', ''], |
||
76 | LogLevel::WARNING => [self::FGCOLOR_BRIGHT_YELLOW, '', ''], |
||
77 | LogLevel::ERROR => [self::FGCOLOR_BRIGHT_RED, '', ''], |
||
78 | LogLevel::CRITICAL => [self::FGCOLOR_BRIGHT_RED, '', self::DECO_UNDERLINE], |
||
79 | LogLevel::ALERT => [self::FGCOLOR_BRIGHT_RED, self::BGCOLOR_WHITE, ''], |
||
80 | LogLevel::EMERGENCY => [self::FGCOLOR_BRIGHT_RED, self::BGCOLOR_WHITE, self::DECO_BLINK], |
||
81 | ); |
||
82 | |||
83 | /** |
||
84 | * {@inheritDoc} |
||
85 | */ |
||
86 | public function format(LogEntryInterface $entry): string |
||
91 | |||
92 | /** |
||
93 | * add ansi color to text |
||
94 | * |
||
95 | * @param string $level |
||
96 | * @param string $text |
||
97 | * @return string |
||
98 | */ |
||
99 | protected function addColor(string $level, string $text): string |
||
106 | } |