解决这个问题:
例子:
流处理程序:
namespace Acme\DemoBundle\Component\Monolog;
use Monolog\Handler\StreamHandler as BaseStreamHandler;
class StreamHandler extends BaseStreamHandler
{
/**
* @{inerhitDoc}
*/
public function write(array $record)
{
if (null === $this->stream) {
// From original monolog stream handler
if (!$this->url) {
throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
}
$dir = dirname($this->url);
if (!is_dir($dir)) {
if(!@mkdir($dir, 0777, TRUE)) {
// Control errors
}
}
}
parent::write($record);
}
}
并覆盖 symfony monolog 包中的基本流处理程序:
<parameter key="monolog.handler.stream.class">Acme\DemoBundle\Component\Monolog\StreamHandler</parameter>
注意:
这是 Symfony 2 包中覆盖独白处理程序的基本示例!