chrisguitarguy / monolog-ecs
在日志消息中添加AWS ECS元数据
v0.1.0
2018-03-13 19:48 UTC
Requires
- php: ~7.1
Requires (Dev)
- monolog/monolog: ~1.0
- phpunit/phpunit: ~7.0
This package is auto-updated.
Last update: 2024-09-23 06:03:39 UTC
README
一组Monolog处理器,为Monolog的$record
中的extra
键添加一些额外的上下文。
更实际地说,这些允许用户在日志中添加有关生成日志消息的服务器或ECS任务的信息。
可用的值是从容器元数据文件中提取的,所有文件键都是以aws_ecs_
为前缀。下面是一些示例
安装
composer require chrisguitarguy/monolog-ecs
用法
use Monolog\Logger; use Monolog\Handler\StreamHandler; use Chrisguitarguy\MonologEcs\AwsEcsProcessor; $logger = new Logger('myapp'); // add the processor, `::create()` uses the default dependencies that loads // metadata from the file and caches it based on the file status $logger->pushProcessor(AwsEcsProcessor::create()); // now use the various `%extra.aws_ecs_*` values as desired. These are all // keys from the metadata file lowercased and prefixed with `aws_ecs_` $handler = new StreamHandler('php://stdout'); $handler->setFormatter(new LineFormatter( '[%datetime%] %channel%.%level_name%: %message% (%extra.aws_ecs_taskarn%, %extra.aws_ecs_containerinstancearn%)' )); $logger->pushHandler($handler);
上述示例将包括ECS任务的ARN以及运行任务的实例的ARN。