Utilities::log( $trace_message = '',  $trace_heading = '',  $force_log = false,  $file_name = 'logs',  $backtrace = false )

Create and store logs @ wp-content/uo-{$file_name}.log


Parameters Parameters

$trace_message

(Optional) The message logged

Default value: ''

$trace_heading

(Optional) The heading of the current trace

Default value: ''

$backtrace

(Optional) Create log even if debug mode is off

Default value: false

$file_name

(Optional) The file name of the log file

Default value: 'logs'


Top ↑

Return Return

(Uncanny_Automator$error_log) Was the log successfully created


Source Source

File: src/core/class-utilities.php

	public static function log( $trace_message = '', $trace_heading = '', $force_log = false, $file_name = 'logs', bool $backtrace = false ) {

		// Only return log if debug mode is on OR if log is forced
		if ( ! self::automator_get_debug_mode() && false === $force_log ) {
			return false;
		}

		$timestamp         = current_time( self::automator_get_date_time_format() ); //phpcs ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
		$current_page_link = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
		$trace_start       = "\n===========================<<<< $timestamp >>>>===========================\n";
		$trace_heading     = "* Heading: $trace_heading \n* Current Page: $current_page_link \n";
		//$trace_end         = "\n===========================<<<< TRACE END >>>>===========================\n";

		$backtrace_start = "\n===========================<<<< BACKTRACE START >>>>===========================\n";
		$error_string    = print_r( ( new \Exception )->getTraceAsString(), true );
		$backtrace_end   = "\n===========================<<<< BACKTRACE END >>>>===========================\n";

		$trace_msg_start = "\n===========================<<<< TRACE MESSAGE START >>>>===========================\n";
		$trace_finish    = "\n===========================<<<< END >>>>===========================\n\n";

		$trace_message = print_r( $trace_message, true );
		$log_directory = UA_DEBUG_LOGS_DIR;
		if ( ! file_exists( $log_directory ) ) {
			mkdir( $log_directory, 0755 );
		}
		$file = $log_directory . 'uo-' . $file_name . '.log';
		if ( ! $backtrace ) {
			$complete_message = $trace_start . $trace_heading . $trace_msg_start . $trace_message . $trace_finish;
		} else {
			$complete_message = $trace_start . $trace_heading . $backtrace_start . $error_string . $backtrace_end . $trace_msg_start . $trace_message . $trace_finish;
		}

		error_log( $complete_message, 3, $file );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.