Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing cache_dir and log_dir with Symfony2

Because of deployment constraints, I would like to have the log and cache directories used by my Symfony2 application somewhere under /var/... in my file system. For this reason, I am looking for a way to configure Symfony and to override the default location for these two directories.

I have seen the kernel.cache_dir and kernel.log_dir and read the class Kernel.php. From what I have seen, I don't think that it is possible to change the dir locations by configuration and I would have to patch the Kernel.php class.

Is that true, or is there a way to achieve what I want without modifying the framework code?

like image 551
Olivier Liechti Avatar asked Sep 09 '11 04:09

Olivier Liechti


3 Answers

Add the following methods to app/AppKernel.php (AppKernel extends Kernel) making them return your preferred paths:

public function getCacheDir()
{
    return $this->rootDir . '/my_cache/' . $this->environment;
}

public function getLogDir()
{
    return $this->rootDir . '/my_logs';
}
like image 176
nuqqsa Avatar answered Oct 17 '22 05:10

nuqqsa


I was happy to find your post, but I was a little bit confused of the unhelping answers.

I got the same problem and found out that the logs are depending on the config parameter kernel.logs_dir.

So I just added it to my config.yml parameters:

kernel.logs_dir: /var/log/symfonyLogs

I hope it will helpfull for you even, if its a late answer.

like image 8
MonocroM Avatar answered Oct 17 '22 03:10

MonocroM


i think the easiest way is to link the folder to another place. We have made this on the prod server but when you develop local perhaps on windows its a bit complicated to set the symlinks.

ln -s /var/cache/ /var/www/project/app/cache

something like this.

like image 6
René Höhle Avatar answered Oct 17 '22 05:10

René Höhle