Automattic\WooCommerce\Internal\Admin\Logging

LogHandlerFileV2::format_entryprotected staticWC 1.0

Builds a log entry text from level, timestamp, and message.

Method of the class: LogHandlerFileV2{}

Hooks from the method

Returns

String. Formatted log entry.

Usage

$result = LogHandlerFileV2::format_entry( $timestamp, $level, $message, $context );
$timestamp(int) (required)
Log timestamp.
$level(string) (required)
emergency|alert|critical|error|warning|notice|info|debug.
$message(string) (required)
Log message.
$context(array) (required)
Additional information for log handlers.

LogHandlerFileV2::format_entry() code WC 9.9.5

protected static function format_entry( $timestamp, $level, $message, $context ) {
	$time_string  = static::format_time( $timestamp );
	$level_string = strtoupper( $level );

	if ( isset( $context['backtrace'] ) && true === filter_var( $context['backtrace'], FILTER_VALIDATE_BOOLEAN ) ) {
		$context['backtrace'] = static::get_backtrace();
	}

	$context_for_entry = $context;
	unset( $context_for_entry['source'] );

	if ( ! empty( $context_for_entry ) ) {
		$formatted_context = wp_json_encode( $context_for_entry, JSON_UNESCAPED_UNICODE );
		$message          .= stripslashes( " CONTEXT: $formatted_context" );
	}

	$entry = "$time_string $level_string $message";

	// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment
	/** This filter is documented in includes/abstracts/abstract-wc-log-handler.php */
	return apply_filters(
		'woocommerce_format_log_entry',
		$entry,
		array(
			'timestamp' => $timestamp,
			'level'     => $level,
			'message'   => $message,
			'context'   => $context,
		)
	);
	// phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment
}