Prepare the handler for usage by Monolog.

@param  \Monolog\Handler\HandlerInterface  $handler
@param  array  $config
@return \Monolog\Handler\HandlerInterface
182053
protected function prepareHandler(HandlerInterface $handler, array $config = [])
    {
        if (! isset($config['formatter'])) {
            $handler->setFormatter($this->formatter());
        } elseif ($config['formatter'] !== 'default') {
            $handler->setFormatter($this->app->make($config['formatter'], $config['formatter_with'] ?? []));
        }

        return $handler;
    }
1120504
protected function executeHandler($handler, array $parameters)
	{
		if($handler instanceof Closure)
		{
			return $this->executeClosureHandler($handler, $parameters);
		}

		$handler = $this->resolveHandler($handler);

		return $this->executeClassHandler($handler, $parameters);
	}
730379
public function addHandler(callable $handler, $name = null)
    {
        if ($name) {
            $this->handlers[$name] = $handler;
        } else {
            $this->handlers[] = $handler;
        }

        return $this;
    }
621710
public static function callback($handler)
    {
        if ($handler instanceof Closure) {
            return $handler;
        }
        if (is_object($handler[0])) {
            return $handler;
        }

        // If the first argument is a class name string,
        // then create the controller object.
        if (is_string($handler[0])) {

            // If users define the constructor arguments in options array.
            $constructArgs = [];
            $rc = new ReflectionClass($handler[0]);
            if (isset($options['constructor_args'])) {
                $con = $handler[0] = $rc->newInstanceArgs($constructArgs);
            } else {
                $con = $handler[0] = $rc->newInstance();
            }

            return $handler;
        }

        throw new LogicException('Unsupported handler type');
    }
518524
public function create($handlerType, $level)
    {
        if (false === array_key_exists('handler', $this->_config)) {
            throw new MonologCreator\Exception(
                'no handler configuration found'
            );
        }

        if (false === array_key_exists($handlerType, $this->_config['handler'])) {
            throw new MonologCreator\Exception(
                'no handler configuration found for handlerType: '
                . $handlerType
            );
        }

        $handler       = null;
        $handlerConfig = $this->_config['handler'][$handlerType];

        // evaluate handler
        if ('stream' === $handlerType) {
            $handler = $this->_createStreamhandler($handlerConfig, $level);
        } elseif ('udp' === $handlerType) {
            $handler = $this->_createUdphandler($handlerConfig, $level);
        } elseif ('redis' === $handlerType) {
            $handler = $this->_createRedisHandler($handlerConfig, $level);
        } else {
            throw new MonologCreator\Exception(
                'handler type: ' . $handlerType . ' is not supported'
            );
        }

        // set formatter
        if (true === array_key_exists('formatter', $handlerConfig)) {
            $handler->setFormatter(
                $this->_formatterFactory->create($handlerConfig['formatter'])
            );
        }

        return $handler;
    }
613778
protected function createSingleDriver(array $config)
    {
        return new Monolog($this->parseChannel($config), [
            $this->prepareHandler(
                new StreamHandler($config['path'], $this->level($config))
            ),
        ]);
    }
380739
public function createLogger(string $id, array $config): LoggerInterface
    {
        if (!isset($this->_loggers[$id])) {
            $handlers = [];
            $processors = [];

            if (isset($config['handlers'])) {
                foreach ($config['handlers'] as $handlerId) {
                    $handlers[$handlerId] = $this->getHandler($handlerId);
                }
            }

            if (isset($config['processors'])) {
                foreach ($config['processors'] as $processorId) {
                    $processors[$processorId] = $this->getProcessor($processorId);
                }
            }

            $this->setLogger(
                $id,
                new Logger(
                    $id,
                    $handlers,
                    $processors,
                    isset($config['timezone']) ?
                        $config['timezone'] :
                        null
                )
            );
        }

        return $this->_loggers[$id];
    }
1005490
protected function handleRequest(Closure $handler, ?RequestInterface $request): ResponseInterface
    {
        $response = call_user_func($handler, $request);

        return $response;
    }
1358975
public function withHandler(RequestHandlerInterface $handler): self
    {
        $pipeline = clone $this;
        $pipeline->handler = $handler;
        $pipeline->position = 0;

        return $pipeline;
    }
125689
protected function createMonologDriver(array $config)
    {
        if (!is_a($config['handler'], HandlerInterface::class, true)) {
            throw new InvalidArgumentException(
                $config['handler'] . ' must be an instance of ' . HandlerInterface::class
            );
        }

        return new Monolog(
            $this->parseChannel($config), [$this->prepareHandler(
                $this->app->make($config['handler'], $config['with'] ?? []), $config
            )]
        );
    }
739986
public function handle($handler = null, array $params = null): ResponseInterface
    {
        $handler = $this->handler($handler);
        $params = $this->params($params);

        $parameters = null;
        if (!$handler instanceof \Closure) {
            [$class, $method] = $this->convert($handler);

            if ($method === null) {
                $key = $handler = $class;
            } else {
                $controller = new $class;
                $handler = [$controller, $method];
                $key = "{$class}::{$method}";
            }

            $parameters = self::optimizeGet($key);
            if ($parameters === false) {
                $parameters = Builder::getCallableParameters($handler, true);
                self::optimizeSet($key, $parameters);
            }
        }

        $result = $this->container->call($handler, $params, $parameters);

        if ($result instanceof ResponseInterface) {
            return $result;
        }

        /** @var Response $response */
        $response = $this->get('response');

        return $response->default($result);
    }
359840
public function setHandler(Handler $handler)
    {
        $this->whoops->popHandler();
        $this->handler = $handler;
        $this->whoops->pushHandler($this->handler);
    }
1211776
public function create(array $config = [])
    {
        if (null === $this->handler) {
            $this->handler = DefaultHandler::create();
        }

        return new Client(
            array_merge_recursive(
                [
                    'verify'  => false,
                    'handler' => $this->handler,
                ],
                $config
            )
        );
    }
347299
public function addHandler(CommandHandlerInterface $handler)
    {
        $this->__queue->enqueue($handler, $handler->getPriority());
        return $this;
    }
788535
public static function create($name, array $config = [], $title = null){
        $handler = call_user_func([MonologHandlerFactory::class,$name], $config, $title);
        
        // Keep newline characters
        $format = ['fleephook', 'hipchat', 'mail', 'mailgun', 'pushover', 'raven', 'slack'];
        
        if(in_array($name, $format)) {
            $handler->setFormatter(new LineFormatter(null, null, true));
        }

        if ($handler instanceof \Monolog\Handler\NativeMailerHandler) {
            $handler->setContentType('text/html');
        }

        return $handler;
    }
1340771
public function add_handler( HandlerInterface $handler, $name = NULL ) {

		( $name === null ) and $name = spl_object_hash( $handler );
		if ( ! is_string( $name ) || array_key_exists( $name, $this->handlers ) ) {
			return $this;
		}

		$this->handlers[ $name ] = $handler;

		return $this;
	}
831516
public function removeHandler($handler)
    {
        if(!is_callable($handler))
            throw new \InvalidArgumentException("Argument 1 of Event->addHandler needs to be a valid callback");

        $i = array_search($handler, $this->_handlers, true);

        if ($i !== false)
            unset($this->_handlers[$i]);

        return $this;
    }