2
votes

I am using symfony 4.1 and monolog 3.3. I have my symfony project in the following directory: /var/www/html/{project_dir}. In production environment I want my logs to be stored inside /tmp/foo instead of standard symfony directory: {project_dir_path}/var/log.

I changed Kernel::getLogDir() method to the following:

public function getLogDir()
{
    return 'prod' === $this->environment
        ? '/tmp/foo'
        : $this->getProjectDir().'/var/log';
}

My production monolog.yaml path looks like this:

path: "%kernel.logs_dir%/%kernel.environment%.log"

My environment for testing issues is set to 'prod'.

When I am debugging, I can see that monolog's log directory is correctly set to /tmp/foo. /tmp/foo has proper access rights (0766) but when I try to log something, the directory contains nothing.

2
You must provide a full verified path for this line /tmp/foo , this will give you the path php $fullVerifiedPath = getcwd(); BlackXero
The full verified path is /tmp/foo.RaspberryJam
concatenate DIRECTORY_SEPARATOR constant at the end of the path StringBlackXero

2 Answers

0
votes

Conceptually, you can't for security reason. But, you can bypass it by creating a symlink inside your project directory for the right directory folder.

Something like:

public function getLogDir()
{
    return 'prod' === $this->environment
        ? '/var/symlink-to-tmp-folder'
        : $this->getProjectDir().'/var/log';
}
0
votes

Solved, simple mistake. I was developing on docker container, having my project directory as a volumine, but /tmp/foo wasn't obviously binded, so logs were just sitting on the container.