CommandSchedulerBundle icon indicating copy to clipboard operation
CommandSchedulerBundle copied to clipboard

Create log path if it does not exist

Open Bruce17 opened this issue 7 years ago • 0 comments

Hi, I configured a log path in my SF2 which does not exist yet (app/logs/scheduler). How about extending the code to try to create the folder first and then check if it's writable (https://github.com/J-Mose/CommandSchedulerBundle/blob/master/Command/ExecuteCommand.php#L95).

Example:

// Before continue, we check that the output file is valid and writable (except for gaufrette)
if (false !== $this->logPath && strpos($this->logPath, 'gaufrette:') !== 0) {
	// Create folder if it does not exist yet.
	// TODO: maybe pass in folder permission and set "0744" (or s.th. else) as fallback.
	if (false === is_dir($this->logPath) && false === mkdir($this->logPath, 0744, true) {
		$output->writeln(
			'<error>Cannot create folder "'.$this->logPath.'". Please change your `log_path` in config.yml'.'</error>'
		);
		return;
	}

	if (false === is_writable($this->logPath)) {
		$output->writeln(
			'<error>'.$this->logPath.
			' not found or not writable. You should override `log_path` in your config.yml'.'</error>'
		);
		return;
	}
}

Bruce17 avatar Mar 08 '17 16:03 Bruce17