我已经在该网站上搜索了问题,但没有找到解决问题的方法,这看起来很简单,但是我被困住了...
我正在将Symfony 4.1与Doctrine-ODM和MonologBundle结合使用。
我想在Monolog中将自定义通道和处理程序定义为rotation_file。
我在下面定义了我的频道和处理程序,但是当我输入终端bin/console debug:container log
时,我没有列出我的自定义处理程序。
这是我的dev / monolog.yaml:
monolog:
channels: ["foo"]
handlers:
foo:
type: rotating_file
path: "kernel.logs_dir%/%kernel_environment%.foo.log"
channels: ["foo"]
max_files: 30
level: DEBUG
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_404s:
# regex: exclude all 404 errors from the logs
- ^/
channels: ["!foo"]
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: warning
console:
type: console
process_psr_3_messages: false
channels:
- "!event"
- "!doctrine"
level: warning
deprecation:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
deprecation_filter:
type: filter
handler: deprecation
max_level: info
channels: ["php"]
此外,我尝试将其绑定到service.yaml中的service上,例如:
services:
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
bind:
$fooLogger: "@monolog.logger.foo"
最后,我将其注入服务:
<?php
declare(strict_types=1);
namespace App\Handler;
use Psr\Log\LoggerInterface;
class FooManager
{
/**
* @var LoggerInterface
*/
protected $fooLogger;
public function __construct(
LoggerInterface $fooLogger
) {
$this->fooLogger = $fooLogger;
}
....
}
我总是会收到此错误: 在ParameterBag.php第100行中:
您已请求一个不存在的参数“ / foo”。
似乎不喜欢我的自定义日志文件路径,但是我想对其进行自定义。如何清除此错误?