Automattic\WooCommerce\Internal\Admin\Logging\FileV2

FileController::write_to_file()publicWC 1.0

Write a log entry to the appropriate file, after rotating the file if necessary.

Method of the class: FileController{}

No Hooks.

Return

true|false. True if the contents were successfully written to the file.

Usage

$FileController = new FileController();
$FileController->write_to_file( $source, $text, ?int $time ): bool;
$source(string) (required)
The source property of the log entry, which determines which file to write to.
$text(string) (required)
The contents of the log entry to add to a file.
?int $time **
-
Default: null

FileController::write_to_file() code WC 9.3.3

public function write_to_file( string $source, string $text, ?int $time = null ): bool {
	if ( is_null( $time ) ) {
		$time = time();
	}

	$file_id = File::generate_file_id( $source, null, $time );
	$file    = $this->get_file_by_id( $file_id );

	if ( $file instanceof File && $file->get_file_size() >= $this->get_file_size_limit() ) {
		$rotated = $this->rotate_file( $file->get_file_id() );

		if ( $rotated ) {
			$file = null;
		} else {
			return false;
		}
	}

	if ( ! $file instanceof File ) {
		$new_path = Settings::get_log_directory() . $this->generate_filename( $source, $time );
		$file     = new File( $new_path );
	}

	return $file->write( $text );
}