欢迎,
我的任务是更改应用程序中记录器的约定。目前,记录器被配置为专用服务。我想在 Symfony 约定中定义记录器,并通过定义 DI 将记录器服务的旧名称指向 monolog.logger.channel 约定中的新名称来确保向后兼容性。我让 Symfony 中的记录器第一次做事,或者谁能给我一个如何做的例子?提前感谢您,我在下面用我当前的配置向您致意:
应用程序/配置/config_dev.yml:
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ['!my_channel']
my_handler:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.my_handler.log"
level: debug
channels: ['my_channel']
console:
type: console
bubble: false
应用程序/config/config_prod.yml:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
channels: ['!my_channel']
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
my_channel:
type: fingers_crossed
action_level: error
handler: my_channel_stream
my_channel_stream:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.my_channel.log"
level: debug
channels: ['my_channel']
src/bundle/Resources/config/logger.yml:
services:
logger:
class: Symfony\Bridge\Monolog\Logger
arguments: [logger]
calls:
- [pushHandler, ['@monolog.handler.console']]
- [pushHandler, ['@logger_handler']]
logger_handler:
class: Monolog\Handler\StreamHandler
arguments: ["%kernel.logs_dir%/%kernel.environment%.cof.log", 200]
src/bundle/Resources/config/config.yml:
monolog:
channels: ['my_channel']