2013-02-25 5 views
3

Symfony 2.2 및 Monolog 패키지를 사용합니다. 독백에서Symfony 2.2 및 Monolog 스트림 핸들러 - 자동 생성 디렉토리

내 핸들러 : 디렉토리가없는 존재하는 경우

monolog: 
    handlers: 
     type: stream 
     path: "%kernel.logs_dir%/%kernel.environment%/my-path/error.log" 
     level: error 

그러나 스트림 핸들러는 자동차, 디렉토리를 만들 수 없습니다. 디렉토리를 자동 생성하는 방법은 무엇입니까? . 이벤트 발송자,하지만 난 ((

감사

답변

3

해결 방법이 문제 독백의 이벤트를 볼 수 없습니다 :

  • 재정의 기본 스트림 핸들러

    • 가 자신의 스트림 핸들러를 작성

    예 :

    스트림 처리기 :

    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([email protected]($dir, 0777, TRUE)) { 
            // Control errors 
           } 
          } 
         } 
    
         parent::write($record); 
        } 
    } 
    

    그리고 심포니 독백 패키지에 기본 스트림 핸들러를 오버라이드 (override) :

    <parameter key="monolog.handler.stream.class">Acme\DemoBundle\Component\Monolog\StreamHandler</parameter> 
    

    주의 : 이 심포니의 기본 예를 재정의 독백 핸들러는 2 패키지!

  • +1

    'Monolog.handler.rotating_file.class'와 비슷한 것을 매개 변수에서 오버라이드하고'RotatingFileHandler' 생성자 다음에 폴더 생성 로직을 수행해야만했습니다. 감사합니다! – GabLeRoux

    +0

    Oo, 감사합니다. 나는 이전에 보지 못했다. – ZhukV

    +0

    FWIW,이 방법은 더 이상 작동하지 않습니다. –