createLogger

@param string                $channel
@param string                $level
@param HandlerInterface|null $handler

@return  Monolog
@throws \Exception
172724
public function createLogger(
        ?string $channel = null,
        ?string $level = null,
        HandlerInterface $handler = null
    ): LoggerInterface {
        $config = $this->config->extract('logs.channels.' . $channel);

        if ($config->get('enabled') === false) {
            return $this->getNullLogger();
        }

        $level = $level ?: $config->get('level', LogLevel::DEBUG);

        $logger = new Monolog($channel);

        if (!$handler) {
            $handlers = [];
            $handlerProfiles = (array) $config->get('handlers', [StreamHandler::class]);

            foreach ($handlerProfiles as $class) {
                $args = [];

                $args['level'] = $level;

                if ($class instanceof ClassMeta) {
                    $args['channel'] = $channel;

                    if (!$class->hasArgument('filename')) {
                        $args['filename'] = $this->getLogFile($channel);
                    }

                    $handler = $this->container->newInstance($class, $args);
                } else {
                    if (is_array($class)) {
                        $args = $class['args'] ?? [];
                        $args['level'] = $class['level'] ?? $level;

                        if (isset($class['file_argument'])) {
                            $args[$class['file_argument']] = $this->getLogFile($channel);
                        }

                        $class = $class['class'];
                    }

                    switch ($class) {
                        case 'stream':
                        case StreamHandler::class:
                            $args['stream'] = $args['stream'] ?? $this->getLogFile($channel);

                            $handler = $this->container->newInstance(
                                StreamHandler::class,
                                $args
                            );
                            break;

                        case 'rotating':
                        case RotatingFileHandler::class:
                            $args['filename'] = $args['filename'] ?? $this->getLogFile($channel);

                            $handler = $this->container->newInstance(
                                RotatingFileHandler::class,
                                $args
                            );
                            break;

                        default:
                            $handler = $this->container->newInstance($class, $args);
                    }
                }

                $handlers[] = $handler;
            }
        } else {
            $handlers = [$handler];
        }

        foreach ($handlers as $handler) {
            $handler->setFormatter(new LineFormatter(null, null, true));

            $logger->pushProcessor(new PsrLogMessageProcessor());

            // Basic string handler
            $logger->pushHandler($handler);
        }

        foreach (GlobalContainer::getHandlers() as $handler) {
            $logger->pushHandler(clone $handler);
        }

        foreach (GlobalContainer::getProcessors() as $processor) {
            $logger->pushProcessor(clone $processor);
        }

        return $logger;
    }
1264291
public function log($message, $level = LogLevel::DEBUG)
    {
        if ($this->logger instanceof LoggerInterface) {
            $this->logger->log($level, $message);
        }
    }
443959
protected function addRecord($level, $message, array $context = array())
    {
        if ($this->handlers->count() < 1) {
            throw new LoggerException('To log a record you must add at least one AbstractHandler object to handle the messages.'
            );
        }

        $record = new Record();
        $record->setLoggerName($this->name);
        $record->setMessage((string)$message);
        $record->setContext($context);
        $record->setLevel($level);
        $record->setDatetime($this->datetime("now"));

        // check if any handler will handle this message
        $canHandle = false;
        foreach ($this->handlers as $handler) {
            if ($handler->canHandle($record)) {
                $canHandle = true;
                break;
            }
        }

        if (!$canHandle) {
            return false;
        }

        /* @var $handler Webiny\HandlerAbstract */
        foreach ($this->handlers as $handler) {
            if ($handler->canHandle($record)) {
                $bubble = $handler->process(clone $record);
                if (!$bubble) {
                    break;
                }
            }
        }

        return true;
    }
125220
public function useSyslog($level = Logger::DEBUG, $name = null)
    {
        $name or $name = $this->name;
        $this->monolog->pushHandler(new Handler\SyslogHandler($name, LOG_USER, $level));

        return $this;
    }
956532
protected function logHandler($level, $message, $context)
    {
        Integration::addBreadcrumb(new Breadcrumb(
            $level,
            Breadcrumb::TYPE_USER,
            'log.' . $level,
            $message,
            empty($context) ? [] : ['params' => $context]
        ));
    }
1344420
private function loggerLevel($level)
    {
        switch ($level) {
            case 'trace':
            case 'debug':
                return Logger::DEBUG;
                break;

            case 'info':
                return Logger::INFO;
                break;

            case 'notice':
                return Logger::NOTICE;
                break;

            case 'warn':
            case 'warning':
                return Logger::WARNING;
                break;

            case 'error':
                return Logger::ERROR;
                break;

            case 'crit':
            case 'critical':
                return Logger::CRITICAL;
                break;

            case 'alert':
                return Logger::ALERT;
                break;

            case 'emergency':
                return Logger::EMERGENCY;
                break;

            default:
                throw new \Exception('Unknown Log Level', 1);
                break;
        }
    }
524114
public static function log($data, $level = LoggerInterface::LEVEL_INFO, $type = null)
    {
        LoggerFactory::logger()->log($data, $level, $type);
    }
820951
private function logEvent($event, $message, $level)
    {
        if ($event === 'not-allowed') {
            $message = sprintf('Method Not Allowed: %s', $message);
        } elseif ($event === 'not-found') {
            $message = sprintf('Page Not Found: %s', $message);
        }

        $this->logger->$level($message);
    }
1189136
public function log($level, $message, array $context = array())
    {
        $context = $this->parseContext($context);
        $trace = $context['trace'];
        $logTime = time();
        $record = new Record($level, $message, $context, $trace, $logTime);
        foreach($this->handlers as $handler)
        {
            $handler->log($record);
        }
    }
141496
public function subscribe($channel, callable $handler)
    {
        $subscription = $this->getSubscriptionForChannel($channel);

        $isSubscriptionLoopActive = true;
        $isPauseEnabled = $this->returnImmediately && ($this->returnImmediatelyPause > 0);

        while ($isSubscriptionLoopActive) {
            $messages = $subscription->pull([
                'grpcOptions' => [
                    'timeoutMillis' => null,
                ],
                'maxMessages' => $this->maxMessages,
                'returnImmediately' => $this->returnImmediately,
            ]);
            if ($isPauseEnabled && empty($messages)) {
                usleep($this->returnImmediatelyPause);
                continue;
            }
            foreach ($messages as $message) {
                /** @var Message $message */
                $payload = Utils::unserializeMessagePayload($message->data());

                if ($payload === 'unsubscribe') {
                    $isSubscriptionLoopActive = false;
                } else {
                    call_user_func($handler, $payload);
                }

                $subscription->acknowledge($message);
            }
        }
    }
631654
public function log($level, $message, array $context = [])
    {
        if (count($this->handlers) === 0) {
            throw new RuntimeException('You must define at least one logging handler, none provided.');
        }

        foreach ($this->handlers as $handler) {

            $this->logs[] = sprintf('[%s] %s', $level, $message);

            $handler->write($level, $message, $context);
        }

        return $this;
    }
649454
public function log($level, $message, array $context = array())
    {
        StaticLogger::setHandler($this->handler);

        $u_level = strtoupper($level);

        if (!in_array($u_level, self::$valid_levels)) {
            throw new InvalidArgumentException("Unknown log level");
        }

        $log_entry = StaticLogger::log($level, $message, $context);

        return $log_entry;
    }
16077
public function log($level, $message, array $context = array()) {
		$fn = $this->callback;
		$fn($level, $message, $context);
		$this->logger()->log($level, $message, $context);
	}
694864
private function createLogger(InputInterface $input, OutputInterface $output)
    {
        $logger = new MonologLogger('CommunityTranslation');
        if (!$input->isInteractive()) {
            $config = $this->app->make('community_translation/config');
            if ($config->get('options.nonInteractiveCLICommands.notify')) {
                $to = $config->get('options.nonInteractiveCLICommands.to');
                if ($to && is_array($to)) {
                    $site = $this->app->make('site')->getSite()->getSiteName();
                    foreach ($to as $toConfig) {
                        $handler = null;
                        if (is_array($toConfig) && isset($toConfig['handler'])) {
                            switch ($toConfig['handler']) {
                                case 'slack':
                                    if (isset($toConfig['apiToken']) && $toConfig['apiToken'] && isset($toConfig['channel']) && $toConfig['channel']) {
                                        $handler = new SlackHandler($toConfig['apiToken'], $toConfig['channel'], 'CommunityTranslation@' . $site);
                                        $lineFormatter = new LineFormatter('%message%');
                                        if (method_exists($lineFormatter, 'allowInlineLineBreaks')) {
                                            $lineFormatter->allowInlineLineBreaks(true);
                                        }
                                        $handler->setFormatter($lineFormatter);
                                    }
                                    break;
                                case 'telegram':
                                    if (isset($toConfig['botToken']) && $toConfig['botToken'] && isset($toConfig['chatID']) && $toConfig['chatID']) {
                                        $handler = new TelegramHandler($toConfig['botToken'], $toConfig['chatID']);
                                    }
                                    break;
                            }
                        }
                        if ($handler !== null) {
                            $handler->setLevel(MonologLogger::ERROR);
                            $logger->pushHandler($handler);
                        }
                    }
                }
            }
        }
        $logger->pushHandler(new ConsoleHandler($output));

        return $logger;
    }
728780
protected function log($message, $level = Logger::INFO)
    {
        $this->logger->log($message, $level);
    }
1298683
public function createLogger($channel)
    {
        Cascade::loadConfigFromArray($this->config);
        $logger = Cascade::getLogger($channel);
        $logger->pushProcessor(new PsrLogMessageProcessor());
        return $logger;
    }
1013494
public function log($level, $message, array $context = [])
    {
        if (is_string($level)) {
            if (!array_key_exists($level, $this->levels)) {
                throw new \Exception("Log level {$level} is not valid. Please use syslog levels instead", 500);
            } else {
                $level = $this->levels[$level];
            }
        }
        if (array_key_exists('exception', $context)) {
            if ($context['exception'] instanceof \Exception) {
                $exc = $context['exception'];
                $message .= " Exception: {$exc->getMessage()}";
                unset($context['exception']);
            } else {
                unset($context['exception']);
            }
        }
        $level = $this->s_levels[$level];

        return  $this->interpolate($message, $context, $level);
    }