WC_Logger::log()publicWC 1.0

Add a log entry.

Method of the class: WC_Logger{}

Hooks from the method

Return

null. Nothing (null).

Usage

$WC_Logger = new WC_Logger();
$WC_Logger->log( $level, $message, $context );
$level(string) (required)
One of the following:
php 'emergency': System is unusable. 'alert': Action must be taken immediately. 'critical': Critical conditions. 'error': Error conditions. 'warning': Warning conditions. 'notice': Normal but significant condition. 'info': Informational messages. 'debug': Debug-level messages.
$message(string) (required)
Log message.
$context(array)
Additional information for log handlers.
Default: array()

WC_Logger::log() code WC 9.4.2

public function log( $level, $message, $context = array() ) {
	if ( ! WC_Log_Levels::is_valid_level( $level ) ) {
		/* translators: 1: WC_Logger::log 2: level */
		wc_doing_it_wrong( __METHOD__, sprintf( __( '%1$s was called with an invalid level "%2$s".', 'woocommerce' ), '<code>WC_Logger::log</code>', $level ), '3.0' );
	}

	if ( $this->should_handle( $level ) ) {
		$timestamp = time();

		foreach ( $this->get_handlers() as $handler ) {
			/**
			 * Filter the logging message. Returning null will prevent logging from occurring since 5.3.
			 *
			 * @since 3.1
			 * @param string $message Log message.
			 * @param string $level   One of: emergency, alert, critical, error, warning, notice, info, or debug.
			 * @param array  $context Additional information for log handlers.
			 * @param object $handler The handler object, such as WC_Log_Handler_File. Available since 5.3.
			 */
			$filtered_message = apply_filters( 'woocommerce_logger_log_message', $message, $level, $context, $handler );

			if ( null !== $filtered_message ) {
				$handler->handle( $timestamp, $level, $filtered_message, $context );
			}
		}
	}
}