public function addLogHandler($type, $options)
    {
        // Throw exception if no handler configuration has been set. FirePHPHandler is the exception, it doesn't
        // have any config options.
        if ($options == []) {
            throw new \Exception('Missing handler configuration!', 1);
        }

        // Set the log level if one wasn't given.
        if (!array_key_exists('log_level', $options)) {
            $options['log_level'] = $this->defaultLogLevel;
        }

        // Allow messages to "bubble-up" the stack to other handlers
        if (!array_key_exists('bubble', $options)) {
            $options['bubble'] = true;
        }

        // Add the requested handler
        switch ($type) {
            case 'file':
                $this->pushHandler(new StreamHandler($options['log_location'],
                                                     $this->loggerLevel($options['log_level']),
                                                     $options['bubble']
                                                    )
                );
                break;

            case 'firebug':
                $this->pushHandler(new FirePHPHandler($this->loggerLevel($options['log_level']), $options['bubble']));
                break;

            case 'syslog':
                $syslog = new SyslogHandler($options['facility'], $options['syslogLevel'], $options['bubble']);
                $formatter = new LineFormatter('%channel%.%level_name%: %message% %context% %extra%');
                $syslog->setFormatter($formatter);
                $this->pushHandler($syslog);
                break;

            case 'mail':
                // Create the Swift_mail transport
                $transport = Swift_SmtpTransport::newInstance(
                    $options['host'],
                    $options['port'], 'ssl')
                        ->setUsername(
                            $options['username'])
                        ->setPassword(
                            $options['password']);

                // Create the Mailer using your created Transport
                $mailer = Swift_Mailer::newInstance($transport);

                // Create a message
                $message = Swift_Message::newInstance($options['subject'])
                    ->setFrom($options['from'])
                    ->setTo($options['to'])
                    ->setBody('', 'text/html');

                $htmlFormatter = new HtmlFormatter();

                $mailStream = new SwiftMailerHandler($mailer,
                                                     $message,
                                                     $this->loggerLevel($options['log_level']),
                                                     $options['bubble']
                );
                $mailStream->setFormatter($htmlFormatter);
                $this->pushHandler($mailStream);
                break;

            case 'sms':
                $twilio = new TwilioHandler($options['account_sid'],
                                            $options['auth_token'],
                                            $options['from_numbers'],
                                            $options['to_numbers'],
                                            $options['log_level'],
                                            $options['bubble']
                );

                $formatter = new LineFormatter('%channel%.%level_name%: %message% %context%');
                $twilio->setFormatter($formatter);

                $this->pushHandler($twilio);
                break;

            default:
                throw new \Exception('Unknown Log Handler', 1);
                break;
        }
    }
public function addLogHandler($type, $options)
    {
        // Throw exception if no handler configuration has been set. FirePHPHandler is the exception, it doesn't
        // have any config options.
        if ($options == []) {
            throw new \Exception('Missing handler configuration!', 1);
        }

        // Set the log level if one wasn't given.
        if (!array_key_exists('log_level', $options)) {
            $options['log_level'] = $this->defaultLogLevel;
        }

        // Allow messages to "bubble-up" the stack to other handlers
        if (!array_key_exists('bubble', $options)) {
            $options['bubble'] = true;
        }

        // Add the requested handler
        switch ($type) {
            case 'file':
                $this->pushHandler(new StreamHandler($options['log_location'],
                                                     $this->loggerLevel($options['log_level']),
                                                     $options['bubble']
                                                    )
                );
                break;

            case 'firebug':
                $this->pushHandler(new FirePHPHandler($this->loggerLevel($options['log_level']), $options['bubble']));
                break;

            case 'syslog':
                $syslog = new SyslogHandler($options['facility'], $options['syslogLevel'], $options['bubble']);
                $formatter = new LineFormatter('%channel%.%level_name%: %message% %context% %extra%');
                $syslog->setFormatter($formatter);
                $this->pushHandler($syslog);
                break;

            case 'mail':
                // Create the Swift_mail transport
                $transport = Swift_SmtpTransport::newInstance(
                    $options['host'],
                    $options['port'], 'ssl')
                        ->setUsername(
                            $options['username'])
                        ->setPassword(
                            $options['password']);

                // Create the Mailer using your created Transport
                $mailer = Swift_Mailer::newInstance($transport);

                // Create a message
                $message = Swift_Message::newInstance($options['subject'])
                    ->setFrom($options['from'])
                    ->setTo($options['to'])
                    ->setBody('', 'text/html');

                $htmlFormatter = new HtmlFormatter();

                $mailStream = new SwiftMailerHandler($mailer,
                                                     $message,
                                                     $this->loggerLevel($options['log_level']),
                                                     $options['bubble']
                );
                $mailStream->setFormatter($htmlFormatter);
                $this->pushHandler($mailStream);
                break;

            case 'sms':
                $twilio = new TwilioHandler($options['account_sid'],
                                            $options['auth_token'],
                                            $options['from_numbers'],
                                            $options['to_numbers'],
                                            $options['log_level'],
                                            $options['bubble']
                );

                $formatter = new LineFormatter('%channel%.%level_name%: %message% %context%');
                $twilio->setFormatter($formatter);

                $this->pushHandler($twilio);
                break;

            default:
                throw new \Exception('Unknown Log Handler', 1);
                break;
        }
    }
public function addLogHandler ( $ type , $ options ) { // Throw exception if no handler configuration has been set. FirePHPHandler is the exception, it doesn't // have any config options. if ( $ options == [ ] ) { throw new \ Exception ( 'Missing handler configuration!' , 1 ) ; } // Set the log level if one wasn't given. if ( ! array_key_exists ( 'log_level' , $ options ) ) { $ options [ 'log_level' ] = $ this -> defaultLogLevel ; } // Allow messages to "bubble-up" the stack to other handlers if ( ! array_key_exists ( 'bubble' , $ options ) ) { $ options [ 'bubble' ] = true ; } // Add the requested handler switch ( $ type ) { case 'file' : $ this -> pushHandler ( new StreamHandler ( $ options [ 'log_location' ] , $ this -> loggerLevel ( $ options [ 'log_level' ] ) , $ options [ 'bubble' ] ) ) ; break ; case 'firebug' : $ this -> pushHandler ( new FirePHPHandler ( $ this -> loggerLevel ( $ options [ 'log_level' ] ) , $ options [ 'bubble' ] ) ) ; break ; case 'syslog' : $ syslog = new SyslogHandler ( $ options [ 'facility' ] , $ options [ 'syslogLevel' ] , $ options [ 'bubble' ] ) ; $ formatter = new LineFormatter ( '%channel%.%level_name%: %message% %context% %extra%' ) ; $ syslog -> setFormatter ( $ formatter ) ; $ this -> pushHandler ( $ syslog ) ; break ; case 'mail' : // Create the Swift_mail transport $ transport = Swift_SmtpTransport :: newInstance ( $ options [ 'host' ] , $ options [ 'port' ] , 'ssl' ) -> setUsername ( $ options [ 'username' ] ) -> setPassword ( $ options [ 'password' ] ) ; // Create the Mailer using your created Transport $ mailer = Swift_Mailer :: newInstance ( $ transport ) ; // Create a message $ message = Swift_Message :: newInstance ( $ options [ 'subject' ] ) -> setFrom ( $ options [ 'from' ] ) -> setTo ( $ options [ 'to' ] ) -> setBody ( '' , 'text/html' ) ; $ htmlFormatter = new HtmlFormatter ( ) ; $ mailStream = new SwiftMailerHandler ( $ mailer , $ message , $ this -> loggerLevel ( $ options [ 'log_level' ] ) , $ options [ 'bubble' ] ) ; $ mailStream -> setFormatter ( $ htmlFormatter ) ; $ this -> pushHandler ( $ mailStream ) ; break ; case 'sms' : $ twilio = new TwilioHandler ( $ options [ 'account_sid' ] , $ options [ 'auth_token' ] , $ options [ 'from_numbers' ] , $ options [ 'to_numbers' ] , $ options [ 'log_level' ] , $ options [ 'bubble' ] ) ; $ formatter = new LineFormatter ( '%channel%.%level_name%: %message% %context%' ) ; $ twilio -> setFormatter ( $ formatter ) ; $ this -> pushHandler ( $ twilio ) ; break ; default : throw new \ Exception ( 'Unknown Log Handler' , 1 ) ; break ; } }
Wraps the creation of log handlers so they can be created in a standard way.

@param string $type    Type of log handler to create
@param array  $options Configuration options for log handler

@throws \Exception
Wraps the creation of log handlers so they can be created in a standard way .