承接 bref/logger 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bref/logger

Composer 安装命令:

composer require bref/logger

包简介

All you need to log with Bref on AWS Lambda

README 文档

README

All you need to log with Bref on AWS Lambda.

Bref/Logger is a lightweight PSR-3 logger for AWS Lambda. Messages are sent to stderr so that they end up in CloudWatch.

Why?

As explained in the Bref documentation, logging in AWS Lambda means logging to stderr. Logs written to stderr are automatically sent to CloudWatch, AWS' solution to collect and view logs.

While classic loggers like Monolog work fine, this logger comes as a simpler and lighter alternative optimized for AWS Lambda. It does not require any configuration and currently contains a single class.

Since it is PSR-3 compliant, Bref/Logger is also compatible with any framework or library consuming a PSR-3 logger.

Installation

composer require bref/logger

Usage

The logger does not require any configuration:

$logger = new \Bref\Logger\StderrLogger();

By default, messages above the info level will be logged, the rest will be discarded.

It is possible to log using any PSR-3 log level, the most common ones being:

$logger->debug('This is a debug message');
$logger->info('This is an info');
$logger->warning('This is a warning');
$logger->error('This is an error');
INFO	This is an info	{"message":"This is an info","level":"INFO"}
WARNING	This is a warning	{"message":"This is a warning","level":"WARNING"}
ERROR	This is an error	{"message":"This is an error","level":"ERROR"}

Messages under info are not logged.

Message placeholders

PSR-3 placeholders can be used to insert information from the $context array into the message without having to concatenate strings manually:

$logger->warning('Invalid login attempt for email {email}', [
    'email' => $email,
]);
WARNING	Invalid login attempt for email johndoe@example.com	{"message":"Invalid login attempt for email johndoe@example.com","level":"WARNING","context":{"email":"johndoe@example.com"}}

Logging exceptions

Exceptions can be logged under the exception key:

try {
   // ...
} catch (\Exception $e) {
    $logger->error('Impossible to complete the action', [
        'exception' => $e,
    ]);
}
ERROR	Impossible to complete the action	{"message":"Impossible to complete the action","level":"ERROR","exception":{"class":"InvalidArgumentException","message":"Impossible to complete the action","code":0,"file":"/var/task/index.php","line":12,"trace":[{"file":"/var/task/index.php","line":86,"function":"main"}]}

Log level

It is possible to change the level above which messages are logged.

For example to log all messages:

$logger = new \Bref\Logger\StderrLogger(\Psr\Log\LogLevel::DEBUG);

bref/logger 适用场景与选型建议

bref/logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.59M 次下载、GitHub Stars 达 33, 最近一次更新时间为 2019 年 03 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「logger」 「psr-3」 「lambda」 「cloudwatch」 「bref」 「aws-lambda」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bref/logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bref/logger 我们能提供哪些服务?
定制开发 / 二次开发

基于 bref/logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.59M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 34
  • 点击次数: 33
  • 依赖项目数: 7
  • 推荐数: 0

GitHub 信息

  • Stars: 33
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-06