Importer.php
4 years ago
WPImporterLogger.php
4 years ago
WPImporterLoggerCLI.php
4 years ago
WXRImportInfo.php
4 years ago
WXRImporter.php
4 years ago
WPImporterLoggerCLI.php
45 lines
| 1 | <?php |
| 2 | namespace ProteusThemes\WPContentImporter2; |
| 3 | |
| 4 | class WPImporterLoggerCLI extends WPImporterLogger { |
| 5 | public $min_level = 'notice'; |
| 6 | |
| 7 | /** |
| 8 | * Logs with an arbitrary level. |
| 9 | * |
| 10 | * @param mixed $level |
| 11 | * @param string $message |
| 12 | * @param array $context |
| 13 | * @return null |
| 14 | */ |
| 15 | public function log( $level, $message, array $context = array() ) { |
| 16 | if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( $this->min_level ) ) { |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | printf( |
| 21 | '[%s] %s' . PHP_EOL, |
| 22 | strtoupper( $level ), |
| 23 | $message |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | public static function level_to_numeric( $level ) { |
| 28 | $levels = array( |
| 29 | 'emergency' => 8, |
| 30 | 'alert' => 7, |
| 31 | 'critical' => 6, |
| 32 | 'error' => 5, |
| 33 | 'warning' => 4, |
| 34 | 'notice' => 3, |
| 35 | 'info' => 2, |
| 36 | 'debug' => 1, |
| 37 | ); |
| 38 | if ( ! isset( $levels[ $level ] ) ) { |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | return $levels[ $level ]; |
| 43 | } |
| 44 | } |
| 45 |