Logger.php (1413B)
1 <?php 2 /** 3 * Logger class used in the One Click Demo Import plugin 4 * 5 * @package ocdi 6 */ 7 8 namespace OCDI; 9 10 class Logger extends \ProteusThemes\WPContentImporter2\WPImporterLoggerCLI { 11 /** 12 * Variable for front-end error display. 13 * 14 * @var string 15 */ 16 public $error_output = ''; 17 18 /** 19 * Overwritten log function from WP_Importer_Logger_CLI. 20 * 21 * Logs with an arbitrary level. 22 * 23 * @param mixed $level level of reporting. 24 * @param string $message log message. 25 * @param array $context context to the log message. 26 */ 27 public function log( $level, $message, array $context = array() ) { 28 // Save error messages for front-end display. 29 $this->error_output( $level, $message, $context = array() ); 30 31 if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( $this->min_level ) ) { 32 return; 33 } 34 35 printf( 36 '[%s] %s' . PHP_EOL, 37 strtoupper( $level ), 38 $message 39 ); 40 } 41 42 43 /** 44 * Save messages for error output. 45 * Only the messages greater then Error. 46 * 47 * @param mixed $level level of reporting. 48 * @param string $message log message. 49 * @param array $context context to the log message. 50 */ 51 public function error_output( $level, $message, array $context = array() ) { 52 if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( 'error' ) ) { 53 return; 54 } 55 56 $this->error_output .= sprintf( 57 '[%s] %s<br>', 58 strtoupper( $level ), 59 $message 60 ); 61 } 62 }