etsglobal/log-bundle
最新稳定版本:v5.1.0
Composer 安装命令:
composer require etsglobal/log-bundle
包简介
README 文档
README
Provides normalized logging and tracing features for all ETSGlobal Symfony applications.
Overview
Main features:
- Automatic logger injection.
- Provide
TokenCollectionutility to enable downstream applications for request tracing from app to app. - Automatically configure
globalandprocesstoken tracing for incoming HTTP requests/responses as well as long-running processes. - Automatically enrich log context with the application name and tracing tokens.
- Processor to change the log level of exceptions, like Symfony's
NotFoundHttpException - Slack handler: An extended version of Monolog's slack handler, with custom message contents, and custom filters.
- Provides a Guzzle middleware to forward tokens through HTTP calls.
- Provides a Symfony HttpClient decorator to forward tokens through HTTP calls.
Installation
- Install the bundle
composer require etsglobal/log-bundle
- Load the bundle
// config/Bundles.php return [ ... ETSGlobal\LogBundle\ETSGlobalLogBundle::class => ['all' => true], ... ];
For Symfony < 4
// app/AppKernel.php $bundles = [ ... new ETSGlobal\LogBundle\ETSGlobalLogBundle(), ... ];
Configuration
Bundle configuration
# config/packages/ets_global_log.yaml ets_global_log: app_name: my-app # Used to filter logs by application. slack_handler: token: "slack API token" channel: "#channel-name" jira_url: "example.jira.com" kibana_url: "kibana.example.com/app/kibana" custom_exceptions_levels: My\Custom\Exception: !php/const Monolog\Logger::INFO
Monolog configuration
If you want to use the slack handler provided by this bundle, add the following configuration:
# config/packages/<env>/monolog.yaml monolog: handlers: ... slack_failure: type: 'whatfailuregroup' members: ['slack'] slack: type: 'service' id: 'ets_global_log.monolog.handler.slack' level: "error"
If you have a file handler, you might want to use the token_collection formatter to add the tracing tokens:
# config/packages/<env>/monolog.yaml monolog: handlers: ... file: type: "rotating_file" path: "%kernel.logs_dir%/%kernel.environment%.log" level: debug formatter: 'ets_global_log.monolog.formatter.token_collection'
Automatic logger injection
Automatic logger injection will try to inject the logger in all services tagged with the ets_global_log.logger_aware tag.
The services hate to implement Psr\Log\LoggerAwareInterface to receive the logger by setter injection.
// src/MyService.php namespace App; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; class MyService implements LoggerAwareInterface { use LoggerAwareTrait; }
# config/services.yaml App\MyService: tags: - { name: "ets_global_log.logger_aware" }
Symfony HttpClient decorator
Install symfony/http-client:
composer require symfony/http-client
Configure your scoped client:
framework: http_client: scoped_clients: my.client: base_uri: 'example.com/api/'
Just inject the my.client HttpClient in your services like normally.
The HttpClientDecorator will decorate the HttpClient to automatically inject the token_global in the request.
Guzzle middleware
Install csa/guzzle-bundle:
composer require csa/guzzle-bundle
Configure HTTP clients with the "token_global" middleware:
# config/packages/cas_guzzle.yaml csa_guzzle: profiler: '%kernel.debug%' logger: true clients: foo: config: base_uri: "http://example.com/api" middleware: ['token_global']
统计信息
- 总下载量: 31.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-19