'critical', 'alert' => 'critical', 'critical' => 'critical', 'error' => 'error', 'warning' => 'warning', 'notice' => 'info', 'info' => 'info', 'debug' => 'info', ); public function emergency( $message, array $context = array() ) { return $this->log( 'emergency', $message, $context ); } public function alert( $message, array $context = array() ) { return $this->log( 'alert', $message, $context ); } public function critical( $message, array $context = array() ) { return $this->log( 'critical', $message, $context ); } public function error( $message, array $context = array() ) { return $this->log( 'error', $message, $context ); } public function warning( $message, array $context = array() ) { return $this->log( 'warning', $message, $context ); } public function notice( $message, array $context = array() ) { return $this->log( 'notice', $message, $context ); } public function info( $message, array $context = array() ) { return $this->log( 'info', $message, $context ); } public function debug( $message, array $context = array() ) { return $this->log( 'debug', $message, $context ); } public function log( $level, $message, array $context = array() ) { $severity = self::MAP[ (string) $level ] ?? 'info'; $message = $this->interpolate( (string) $message, $context ); return APWPM_Logger::log( array( 'action_type' => sanitize_key( $context['_action'] ?? ( 'psr3_' . $level ) ), 'object_type' => sanitize_key( $context['_object_type'] ?? 'log' ), 'object_id' => isset( $context['_object_id'] ) ? (int) $context['_object_id'] : 0, 'object_title' => isset( $context['_object_title'] ) ? (string) $context['_object_title'] : '', 'description' => $message, 'severity' => $severity, 'context' => $context, ) ); } protected function interpolate( $message, array $context = array() ) { $replace = array(); foreach ( $context as $k => $v ) { if ( is_scalar( $v ) || ( is_object( $v ) && method_exists( $v, '__toString' ) ) ) { $replace[ '{' . $k . '}' ] = (string) $v; } } return strtr( $message, $replace ); } public static function get_logger() { return new self(); } }