Automattic\WooCommerce\Internal\Admin\Logging\FileV2
FileController::write_to_file
Write a log entry to the appropriate file, after rotating the file if necessary.
Method of the class: FileController{}
No Hooks.
Returns
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() FileController::write to file code WC 11.0.1
public function write_to_file( string $source, string $text, ?int $time = null ): bool {
if ( is_null( $time ) ) {
$time = time();
}
$path = Settings::get_log_directory() . $this->generate_filename( $source, $time );
$file = new File( $path );
$size = $file->get_file_size();
if ( false !== $size && $size >= $this->get_file_size_limit() ) {
if ( ! $this->rotate_file( $file ) ) {
return false;
}
$file = new File( $path );
}
return $file->write( $text );
}