Reputation: 159
I'm using symfony for a cron run application that runs every day
I want to use monolog to write an info
report that I can then email, so I'm looking for a way to separate the files by session id. Example:
report:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%-%sessionid%.log"
level: info
Can this be done?
Upvotes: 1
Views: 370
Reputation: 2063
You have to override the AppKernel
:
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
protected $sessionId;
public function __construct($environment, $debug, $sessionId)
{
$this->sessionId = $sessionId;
parent::_construct($environment, $debug);
}
/**
* {@inheritdoc}
* @see \Symfony\Component\HttpKernel\Kernel::getKernelParameters()
*/
protected function getKernelParameters()
{
$parameters = parent::getKernelParameters();
// Adding session_id parameter
$parameters['kernel.session_id'] = $this->sessionId;
return $parameters;
}
/**
* Your function here [...]
**
}
Now you can use %kernel.session_id%
in your config.yml
monolog:
handlers:
report:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%-%kernel.session_id%.log"
level: info
And in your app.php
:
$sessionId = '123';
$kernel = new AppKernel('prod', false, $sessionId);
You just have to pass $sessionId
as an argument of your script
Upvotes: 1