国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

monolog WebProcessor 在webman中無法獲取ip等參數(shù),日志中該如何獲取請求參數(shù)等內(nèi)容呢

聽淚無言

monolog WebProcessor 在webman中無法獲取ip等參數(shù)
protected $extraFields = [
'url' => 'REQUEST_URI',
'ip' => 'REMOTE_ADDR',
'http_method' => 'REQUEST_METHOD',
'server' => 'SERVER_NAME',
'referrer' => 'HTTP_REFERER',
];

1983 2 0
2個回答

Tinywan

你這是在哪里設(shè)置的?

  • 聽淚無言 2022-03-03

    support\Log.php中channel方法里加了一行$logger->pushProcessor(new WebProcessor());

  • 聽淚無言 2022-03-03
    public static function channel($name = 'default')
    {
        if (!static::$_instance) {
            $configs = config('log', []);
            foreach ($configs as $channel => $config) {
                $logger = static::$_instance[$channel] = new Logger($channel);
                foreach ($config['handlers'] as $handler_config) {
                    $handler = new $handler_config['class'](... \array_values($handler_config['constructor']));
                    if (isset($handler_config['formatter'])) {
                        $formatter = new $handler_config['formatter']['class'](... \array_values($handler_config['formatter']['constructor']));
                        $handler->setFormatter($formatter);
                    }
                    $logger->pushHandler($handler);
                    $logger->pushProcessor(new WebProcessor());
                }
            }
        }
        return static::$_instance[$name];
    }
聽淚無言

已解決 重寫了WebProcessor
如有問題請指正,謝謝
代碼如下
<?php

namespace support;

class WebProcessor extends \Monolog\Processor\WebProcessor
{
protected $extraFields = [
'url' => 'REQUEST_URI',
'ip' => 'REMOTE_ADDR',
'http_method' => 'REQUEST_METHOD',
'header' => 'REQUEST_HEADER',
'get' => 'REQUEST_GET',
'post' => 'REQUEST_POST',
];

public function __invoke(array $record): array
{
    $this->serverData['REQUEST_URI'] = request()->url();
    $this->serverData['REMOTE_ADDR'] = request()->getRealIp();
    $this->serverData['REQUEST_METHOD'] = request()->method();
    $this->serverData['REQUEST_HEADER'] = request()->header();
    $this->serverData['REQUEST_GET'] = request()->get();
    $this->serverData['REQUEST_POST'] = request()->post();
    if (!isset($this->serverData['REQUEST_URI'])) {
        return $record;
    }
    $record['extra'] = $this->appendExtraFields($record['extra']);

    return $record;
}

private function appendExtraFields(array $extra): array
{
    foreach ($this->extraFields as $extraName => $serverName) {
        $extra[$extraName] = $this->serverData[$serverName] ?? null;
    }

    return $extra;
}

}

  • 暫無評論
年代過于久遠(yuǎn),無法發(fā)表回答
??