bexlardi / symfonylogbundle
Symfony 日志包
Requires
- php: >=7.0.0
- symfony/monolog-bundle: ^3.0.2
This package is auto-updated.
Last update: 2024-09-29 05:36:11 UTC
README
安装
在文件 composer.json 中
- 在所需组件中添加依赖 => "bexlardi/symfonylogbundle": "^1.0"
更新 composer 依赖 => composer update
在文件 AppKernel 中,添加包 => new LogBundle\BexlardiLogBundle()
在配置文件(config_dev.yml 和 config_prod.yml 默认),在 monolog/handlers/main 中添加以下行 => formatter: monolog.formatter.session_request
用法
调用服务 pharmagest.logger.service(依赖注入或 $this->container->get('pharmagest.logger.service'))。
添加一个手动线程到日志(默认为 'Symfony'):$this->logger->setThread($string);
示例:$this->logger->setThread('CoreBundle');
全局添加键值对(多个日志间共享): $this->logger->setGlobalKeysValues($array);
示例:$this->logger->setGlobalKeysValues([
'service' => 'UpdateService',
'function' => 'updateMaterializedViews',
'target' => $target
]);
创建日志消息:$this->logger->logMsg(String $level, String $message, Array $extra);
$this->logger->logMsg('info', '日志消息', [
'target' => $target
]);
如果用户已认证,则自动添加包含用户 id 的 user 字段。
需求
Symfony 3 或 4,PHP 7