$context Extra context. */ public function info( string $message, array $context = array() ): void { $this->log( 'info', $message, $context ); } /** * Log a warning. * * @param string $message Message. * @param array $context Extra context. */ public function warning( string $message, array $context = array() ): void { $this->log( 'warning', $message, $context ); } /** * Log an error. Errors are always recorded regardless of the enabled flag. * * @param string $message Message. * @param array $context Extra context. */ public function error( string $message, array $context = array() ): void { $this->log( 'error', $message, $context, true ); } /** * Write a log entry. * * @param string $level Log level. * @param string $message Message. * @param array $context Extra context. * @param bool $force Bypass the enabled gate (for errors). */ private function log( string $level, string $message, array $context, bool $force = false ): void { if ( ! $force && ! $this->is_enabled() ) { return; } if ( array() !== $context ) { $message .= ' ' . wp_json_encode( $context ); } if ( function_exists( 'wc_get_logger' ) ) { wc_get_logger()->log( $level, $message, array( 'source' => self::SOURCE ) ); return; } // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log error_log( sprintf( '[%s][%s] %s', self::SOURCE, $level, $message ) ); } }