silpion/logger-extra-bundle
Composer 安装命令:
composer require silpion/logger-extra-bundle
包简介
Extra logging features for Monolog in a Symfony2 bundle.
README 文档
README
Symfony2 Bundle for Logging related functionality. This bundle can give you these features:
- Add a unique RequestId to each message of the current request.
- Add a unique SessionId to each message dependent on current session id.
- Add arbitrary "key: value" pairs to each message of the current request.
- Create a log entry on a MASTER Request.
- Create a log entry on a Response.
There is also a Stack Middleware for logging Requests and Responses: silpion/stack-logger
Installation
Using Composer:
php composer.phar require silpion/logger-extra-bundle
Also add SilpionLoggerExtraBundle to your AppKernel:
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
...
new Silpion\LoggerExtraBundle\SilpionLoggerExtraBundle(),
);
...
}
}
Configuration
By default, this bundle will not do anything! Every feature has to be enabled on its own.
Example configuration:
silpion_logger_extra:
# If a random request_id should be added to the [extra] section of each log message.
request_id: true
# Class of the used request_id provider.
request_id_provider: Silpion\LoggerExtraBundle\Logger\Provider\Request\UniqRequestIdProvider
# If a salted SHA1 of the session_id should be added to the [extra] section of each log message.
session_id: true
# Class of the used session_id provider.
session_id_provider: Silpion\LoggerExtraBundle\Logger\Provider\Session\SymfonySessionIdProvider
# If the current PID of the PHP Interpreter should be added to the [extra] section of each log message.
process_id: true
# If the session should be started, so the session_id will always be available.
session_start: false
# A list of "key: value" entries that will be set in the [extra] section of each log message (Overwrites existing keys!).
additions:
server_id: 42
logger:
# Will create a log entry on each incoming request.
on_request: true
# Will create a log entry on each outgoing response.
on_response: true
Available Providers
RequestIdProvider
Next to the UniqRequestIdProvider, which will generate a simple sha1 hash,
there is also the EnrichedRequestIdProvider that will generate MongoDb ObjectId like hashes containing the current timestamp, machineId, processId.
The EnrichedRequestIdProvider will generate request_id, that will be sortable by creation time.
Usage
If you want to use the current RequestId or SessionId somewhere in your application, see this code:
$requestId = $this->get('silpion_logger_extra')->getRequestId();
$sessionId = $this->get('silpion_logger_extra')->getSessionId();
References
Funny enough a example for adding a RequestId is in a Symfony2 Cookbook, but not available in a bundle till now.
统计信息
- 总下载量: 3.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-03-07