Monologger 中的 "channel" 是什么?
What is "channel" in Monologger?
我正在努力学习Monolog and I am following this tutorial: https://stackify.com/php-monolog-tutorial/
它说
First, when you create a logger, channel name should be included, so that you can distinguish your list of loggers.
$logger = new MonologLogger('channel-name');
$app->container->logger = $logger;
In the example above, ‘channel-name’ should be included in every log entry. This way you can easily look up and filter the entries; create another channel for each component. Examples of these channels might include ‘database’, ‘security’, ’business’, and others.
那么到底什么是渠道,我应该如何使用它们?
这里的“频道”不是一个通用的PHP概念,它只是 monolog 用于表示您要记录的一类消息的术语。
来自the monolog usage documentation:
You can create many Loggers, each defining a channel (e.g.: db, request, router, ..) and each of them combining various handlers, which can be shared or not. The channel is reflected in the logs and allows you to easily see or filter records.
再往下就是 another section on using channels:
Channels are a great way to identify to which part of the application a record is related. This is useful in big applications (and is leveraged by MonologBundle in Symfony).
Picture two loggers sharing a handler that writes to a single log file. Channels would allow you to identify the logger that issued every record. You can easily grep through the log files filtering this or that channel.
简单来说,您可以将通道定义为单独的日志文件。
通常您可能需要针对不同的服务或模块对日志文件进行分类。
为此,Monolog 允许您创建不同的频道,每个频道可以分别记录到不同的文件,并允许您为每个频道配置您的日志。
在您所指的行中
$logger = new MonologLogger('channel-name');
$app->container->logger = $logger;
您正在 Monologger 的构造函数中指定频道。
任何时候你使用这个 $logger 对象,它都会写入你在配置通道时指定的文件。下面是来自 Symfony 文档的频道配置示例
monolog:
handlers:
security:
# log all messages (since debug is the lowest level)
level: debug
type: stream
path: '%kernel.logs_dir%/security.log'
channels: [security]
在这种情况下,您可以在代码中执行此操作以使用频道
$logger = new MonologLogger('security');
然后您将登录到 "security.log",类型为 "stream" 的错误级别为 "debug"。
我正在努力学习Monolog and I am following this tutorial: https://stackify.com/php-monolog-tutorial/
它说
First, when you create a logger, channel name should be included, so that you can distinguish your list of loggers.
$logger = new MonologLogger('channel-name'); $app->container->logger = $logger;
In the example above, ‘channel-name’ should be included in every log entry. This way you can easily look up and filter the entries; create another channel for each component. Examples of these channels might include ‘database’, ‘security’, ’business’, and others.
那么到底什么是渠道,我应该如何使用它们?
这里的“频道”不是一个通用的PHP概念,它只是 monolog 用于表示您要记录的一类消息的术语。
来自the monolog usage documentation:
You can create many Loggers, each defining a channel (e.g.: db, request, router, ..) and each of them combining various handlers, which can be shared or not. The channel is reflected in the logs and allows you to easily see or filter records.
再往下就是 another section on using channels:
Channels are a great way to identify to which part of the application a record is related. This is useful in big applications (and is leveraged by MonologBundle in Symfony).
Picture two loggers sharing a handler that writes to a single log file. Channels would allow you to identify the logger that issued every record. You can easily grep through the log files filtering this or that channel.
简单来说,您可以将通道定义为单独的日志文件。
通常您可能需要针对不同的服务或模块对日志文件进行分类。
为此,Monolog 允许您创建不同的频道,每个频道可以分别记录到不同的文件,并允许您为每个频道配置您的日志。
在您所指的行中
$logger = new MonologLogger('channel-name');
$app->container->logger = $logger;
您正在 Monologger 的构造函数中指定频道。
任何时候你使用这个 $logger 对象,它都会写入你在配置通道时指定的文件。下面是来自 Symfony 文档的频道配置示例
monolog:
handlers:
security:
# log all messages (since debug is the lowest level)
level: debug
type: stream
path: '%kernel.logs_dir%/security.log'
channels: [security]
在这种情况下,您可以在代码中执行此操作以使用频道
$logger = new MonologLogger('security');
然后您将登录到 "security.log",类型为 "stream" 的错误级别为 "debug"。