creates specific monolog handlers

@param string $handlerType
@param string $level

@return Monolog\Handler\HandlerInterface

@throws MonologCreator\Exception
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;
    }
647376
public static function log($message, $level = Logger::INFO)
    {
        if (! self::$logger) {
            $logfile = sprintf('%s%sarrowsphere-client.log', sys_get_temp_dir(), DIRECTORY_SEPARATOR);
            
            // create a log channel
            self::$logger = new Logger('xAC');
            self::$logger->pushHandler(new StreamHandler($logfile, Logger::INFO));
        }
        
        return self::$logger->addRecord($level, $message);
    }
1162784
public function getLogger(string $channel, ?string $level = null): LoggerInterface
    {
        $channel = strtolower($channel);

        if (!isset($this->loggers[$channel])) {
            if (class_exists(Monolog::class)) {
                $this->loggers[$channel] = $this->createLogger($channel, $level);

                return $this->loggers[$channel];
            }

            return $this->getNullLogger();
        }

        return $this->loggers[$channel];
    }
1192430
public function getHandlerForType(string $type) : HandlerInterface
    {
        if ($this->hasHandlerForType($type)) {
            return $this->handlers[$type];
        }

        throw DataTypeException::handlerNotFound($type);
    }
345107
public static function setHandler($level = null, $handler = null)
    {
        if (empty($level)) {
            $level = static::DEFAULT_LEVEL;
        }

        if (!empty($handler)) {
            static::$handler = $handler;
            return;
        }

        static::$handler = new \Monolog\Handler\StdoutHandler(constant("\Monolog\Logger::$level"));
        static::$handler->setFormatter(static::getFormatter());
    }
1369486
public static function log($loggable, $level, array $context = []) {
        self::init();

        // Wrap everything in a try-catch block to prevent user generated log messages from getting lost if logging fails.
        try {
            // block recursive calls
            // TODO: instead of recursive calls block duplicate messages
            static $isActive = false;
            if ($isActive) throw new RuntimeException('Detected recursive call of '.__METHOD__.'(), aborting...');
            $isActive = true;                                           // lock the method

            // validate parameters
            if (!is_string($loggable)) {
                if (!is_object($loggable))                   throw new IllegalTypeException('Illegal type of parameter $loggable: '.gettype($loggable));
                if (!method_exists($loggable, '__toString')) throw new IllegalTypeException('Illegal type of parameter $loggable: '.get_class($loggable).'::__toString() not found');
                if (!$loggable instanceof \Exception)
                    $loggable = (string) $loggable;
            }
            if (!is_int($level))                            throw new IllegalTypeException('Illegal type of parameter $level: '.gettype($level));
            if (!isset(self::$logLevels[$level]))           throw new InvalidArgumentException('Invalid argument $level: '.$level.' (not a loglevel)');

            $filtered = false;

            // filter messages below the active loglevel
            if (!$filtered && $level!=L_FATAL) {                                // L_FATAL (highest) can't be below
                if (!key_exists('class', $context))                             // resolve the calling class and check its loglevel
                    self::resolveLogCaller($context);
                $filtered = $level < self::getLogLevel($context['class']);      // message is below the active loglevel
            }

            // filter "headers already sent" errors triggered by a previously printed HTML log message
            if (!$filtered && !CLI && self::$printCounter && $loggable instanceof \Exception) {
                if (preg_match('/- headers already sent (by )?\(output started at /', $loggable->getMessage())) {
                    $filtered = true;
                }
            }

            // invoke all active log handlers
            if (!$filtered) {
                if ($level == L_FATAL) $printHandler = 'printFatalHandler';
                else                   $printHandler = 'printNonfatalHandler';

                self::${$printHandler} && self::invokePrintHandler   ($loggable, $level, $context);
                self::$mailHandler     && self::invokeMailHandler    ($loggable, $level, $context);
                self::$smsHandler      && self::invokeSmsHandler     ($loggable, $level, $context);
                self::$errorLogHandler && self::invokeErrorLogHandler($loggable, $level, $context);
            }

            // unlock the method
            $isActive = false;

        }
        catch (\Exception $ex) {
            // Prevent user generated log messages from getting lost if logging fails. In the context of this method
            // only exceptions logged with L_FATAL are not user generated (i.e. they are generated by the registered
            // exception handler).
            if ($level!=L_FATAL || !$loggable instanceof \Exception) {
                $file = key_exists('file', $context) ? $context['file'] : '';
                $line = key_exists('line', $context) ? $context['line'] : '';
                $msg  = 'PHP ['.strtoupper(self::$logLevels[$level]).'] '.$loggable.NL.' in '.$file.' on line '.$line;
                error_log(trim($msg), ERROR_LOG_DEFAULT);
            }
            throw $ex;
        }
    }
1205315
public function createHandlers(array $loggerConfig)
    {
        $handlers         = array();
        $formatterFactory = new MonologCreator\Factory\Formatter(
            $this->_config
        );
        $handlerFactory   = new MonologCreator\Factory\Handler(
            $this->_config,
            $this->_levels,
            $formatterFactory
        );

        foreach ($loggerConfig['handler'] as $handlerType) {
            $handlers[] = $handlerFactory->create(
                $handlerType,
                $loggerConfig['level']
            );
        }

        return $handlers;
    }
746811
protected function getStreamHandler(FormatterInterface $formatter, $stream, $level = Logger::DEBUG, $bubble = true)
    {
        // Unless cli, force output to php://output
        $stream = Director::is_cli() ? $stream : 'php://output';
        $handler = Injector::inst()->createWithArgs(
            StreamHandler::class,
            array($stream, $level, $bubble)
        );
        $handler->setFormatter($formatter);
        return $handler;
    }
778742
public function log($level, $message, array $context = [])
    {
        $record = $this->prepareRecord($level, $message, $context);
        
        $iterator = $this->handlers->getIterator();
        
        while ($iterator->valid()) {
            /** @var HandlerInterface $handler */
            $handler = $iterator->current();
            
            if ($handler->levelAllow($level)) {
                $handler->handle($record);
            }
            
            $iterator->next();
        }
        
        return true;
    }
1118336
public static function createFromException($e, $level, array $context = [])
    {
        return new static($e->getMessage(), $level, $context, $e->getCode(), $e->getPrevious());
    }
849850
public function logLevel($level)
    {
        if (!is_numeric($level)) {
            return $level;
        }

        try {
            return ucfirst(strtolower(\Monolog\Logger::getLevelName($level)));
        } catch (\Exception $e) {
            return $level;
        }
    }
129875
public function log($message, array $context = array(), $level = Logger::INFO)
    {
        return $this['monolog']->addRecord($level, $message, $context);
    }
624113
public function create($formatterType)
    {
        if (false === array_key_exists('formatter', $this->_config)) {
            throw new MonologCreator\Exception(
                'no formatter configuration found'
            );
        }

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

        $formatterConfig = $this->_config['formatter'][$formatterType];

        if ('logstash' === $formatterType) {
            return $this->_createLogstash($formatterConfig);
        }

        if ('line' === $formatterType) {
            return $this->_createLine($formatterConfig);
        }

        throw new MonologCreator\Exception(
            'formatter type: ' . $formatterType . ' is not supported'
        );
    }
768048
public function log($level, $message, array $context = array())
    {
        $logger = new \Monolog\Logger('audit');
        try {
            $handler = new \Monolog\Handler\MongoDBHandler(
                new \Mongo($this->getConnectString()),
                $this->getDbName(),
                $this->getDbCollection()
            );
        } catch (\MongoConnectionException $e) {
            throw new \Exception('Cannot connect to Mongo - please check your server');
        }
        $logger->pushHandler($handler);
        $logger->pushProcessor(function ($record) {
            $record['datetime'] = $record['datetime']->format('U');
            return $record;
        });

        return $logger->$level($message, $context);
    }
1092647
public function handleException(Exception $exception, $level = 'warning', array $context = array())
    {
        $title = 'Handle Exception: '. $level;
        $messageException = $exception->getMessage();
        $message = $this->formatNotification->formatMessage($title, false, $messageException);
        $this->logger->$level($message, $context);

        $this->dispatcher->dispatch(
            $exception instanceof DispatchableException ? $exception->getEventName() : 'exception.thrown',
            new ThrowException($exception)
        );
    }
882774
public function createDefaultChromePHPLogger($name, $level = Logger::DEBUG)
    {
        $logger = new Logger($name);
        $handler = new \Monolog\Handler\ChromePHPHandler($level);
        $logger->pushHandler($handler);
        $this->loggers[$name] = $logger;

        return $this;
    }
1292880
protected function triggerLogEvent($level, $message, array $context = array())
	{
		// If the event dispatcher is set, we will pass along the parameters to the
		// log listeners. These are useful for building profilers or other tools
		// that aggregate all of the log messages for a given "request" cycle.
		if ($this->dispatcher instanceof DispatcherInterface)
		{
			$this->dispatcher->trigger('onLog', array($level, $message, $context));
		}
	}