$context Context data. */ public static function log( $message, $level = 'info', $context = [] ) { wcpay_get_container()->get( InternalLogger::class )->log( $message, $level, $context ); } /** * Checks if the gateway setting logging toggle is enabled. * * @return bool Depending on the enable_logging setting. */ public static function can_log() { return wcpay_get_container()->get( InternalLogger::class )->can_log(); } /** * Creates a log entry of type emergency * * @param string $message To send to the log file. */ public static function emergency( $message ) { self::log( $message, 'emergency' ); } /** * Creates a log entry of type alert * * @param string $message To send to the log file. */ public static function alert( $message ) { self::log( $message, 'alert' ); } /** * Creates a log entry of type critical * * @param string $message To send to the log file. */ public static function critical( $message ) { self::log( $message, 'critical' ); } /** * Creates a log entry of type error * * @param string $message To send to the log file. */ public static function error( $message ) { self::log( $message, 'error' ); } /** * Creates a log entry of type warning * * @param string $message To send to the log file. */ public static function warning( $message ) { self::log( $message, 'warning' ); } /** * Creates a log entry of type notice * * @param string $message To send to the log file. */ public static function notice( $message ) { self::log( $message, 'notice' ); } /** * Creates a log entry of type info * * @param string $message To send to the log file. */ public static function info( $message ) { self::log( $message, 'info' ); } /** * Creates a log entry of type debug * * @param string $message To send to the log file. */ public static function debug( $message ) { self::log( $message, 'debug' ); } /** * Formats an object for logging. * * @param string $label Label for the object. * @param mixed $object Object to format. * @return string */ public static function format_object( $label, $object ) { try { $encoded = wp_json_encode( $object, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR ); } catch ( \JsonException $e ) { return sprintf( 'Error encoding object "%s": %s', $label, $e->getMessage() ); } return sprintf( '%s (JSON): %s', $label, $encoded ); } }