WpCliLogger.php
164 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WpMatomo\WpStatistics\Logger; |
| 4 | |
| 5 | use WP_CLI; |
| 6 | use Psr\Log\LoggerInterface; |
| 7 | |
| 8 | /** |
| 9 | * WP_CLi logger |
| 10 | * |
| 11 | * @package WpMatomo |
| 12 | * @subpackage WpStatisticsImport |
| 13 | */ |
| 14 | class WpCliLogger implements LoggerInterface { |
| 15 | |
| 16 | public function debug( $message, array $context = array() ) { |
| 17 | WP_CLI::log( |
| 18 | '[debug] ' . str_replace( |
| 19 | array_map( |
| 20 | [ |
| 21 | $this, |
| 22 | 'getContext', |
| 23 | ], |
| 24 | array_keys( $context ) |
| 25 | ), |
| 26 | array_values( $context ), |
| 27 | $message |
| 28 | ) |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | public function error( $message, array $context = array() ) { |
| 33 | WP_CLI::log( |
| 34 | '[error] ' . str_replace( |
| 35 | array_map( |
| 36 | [ |
| 37 | $this, |
| 38 | 'getContext', |
| 39 | ], |
| 40 | array_keys( $context ) |
| 41 | ), |
| 42 | array_values( $context ), |
| 43 | $message |
| 44 | ) |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | public function critical( $message, array $context = array() ) { |
| 49 | WP_CLI::log( |
| 50 | '[critical] ' . str_replace( |
| 51 | array_map( |
| 52 | [ |
| 53 | $this, |
| 54 | 'getContext', |
| 55 | ], |
| 56 | array_keys( $context ) |
| 57 | ), |
| 58 | array_values( $context ), |
| 59 | $message |
| 60 | ) |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | public function warning( $message, array $context = array() ) { |
| 65 | WP_CLI::log( |
| 66 | '[warning] ' . str_replace( |
| 67 | array_map( |
| 68 | [ |
| 69 | $this, |
| 70 | 'getContext', |
| 71 | ], |
| 72 | array_keys( $context ) |
| 73 | ), |
| 74 | array_values( $context ), |
| 75 | $message |
| 76 | ) |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | public function info( $message, array $context = array() ) { |
| 81 | WP_CLI::log( |
| 82 | '[info] ' . str_replace( |
| 83 | array_map( |
| 84 | [ |
| 85 | $this, |
| 86 | 'getContext', |
| 87 | ], |
| 88 | array_keys( $context ) |
| 89 | ), |
| 90 | array_values( $context ), |
| 91 | $message |
| 92 | ) |
| 93 | ); |
| 94 | } |
| 95 | |
| 96 | public function log( $level, $message, array $context = array() ) { |
| 97 | WP_CLI::log( |
| 98 | '[' . $level . '] ' . str_replace( |
| 99 | array_map( |
| 100 | [ |
| 101 | $this, |
| 102 | 'getContext', |
| 103 | ], |
| 104 | array_keys( $context ) |
| 105 | ), |
| 106 | array_values( $context ), |
| 107 | $message |
| 108 | ) |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | public function notice( $message, array $context = array() ) { |
| 113 | WP_CLI::log( |
| 114 | '[notice] ' . str_replace( |
| 115 | array_map( |
| 116 | [ |
| 117 | $this, |
| 118 | 'getContext', |
| 119 | ], |
| 120 | array_keys( $context ) |
| 121 | ), |
| 122 | array_values( $context ), |
| 123 | $message |
| 124 | ) |
| 125 | ); |
| 126 | } |
| 127 | |
| 128 | public function alert( $message, array $context = array() ) { |
| 129 | WP_CLI::log( |
| 130 | '[alert] ' . str_replace( |
| 131 | array_map( |
| 132 | [ |
| 133 | $this, |
| 134 | 'getContext', |
| 135 | ], |
| 136 | array_keys( $context ) |
| 137 | ), |
| 138 | array_values( $context ), |
| 139 | $message |
| 140 | ) |
| 141 | ); |
| 142 | } |
| 143 | |
| 144 | public function emergency( $message, array $context = array() ) { |
| 145 | WP_CLI::log( |
| 146 | '[emergency] ' . str_replace( |
| 147 | array_map( |
| 148 | [ |
| 149 | $this, |
| 150 | 'getContext', |
| 151 | ], |
| 152 | array_keys( $context ) |
| 153 | ), |
| 154 | array_values( $context ), |
| 155 | $message |
| 156 | ) |
| 157 | ); |
| 158 | } |
| 159 | |
| 160 | public function getContext( $context ) { |
| 161 | return '{' . $context . '}'; |
| 162 | } |
| 163 | } |
| 164 |