定制 beyounglabs/monolog-stackdriver 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

beyounglabs/monolog-stackdriver

Composer 安装命令:

composer require beyounglabs/monolog-stackdriver

包简介

Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).

README 文档

README

This package enables you to push your Monolog log entries to Stackdriver which is part of the Google Cloud Platform.

The supplied StackdriverHandler copies the given log level into the Stackdriver's severity based on your log method.

It also respects the context argument which allows you to send extra contextual data with your log message. This will be stored in the log message under jsonPayload.data.

Configuration

Service account

With our samples we assume you have a service account Google Developers Console JSON key file available within your project to point at with read rights.

If you don't have this file yet, you can create it via Google Cloud Platform - IAM & Admin - Service accounts. Please make sure you have at least the role of Logs writer enabled.

Google\Cloud\Logging\LoggingClient options

Please read the documentation for the Google\Cloud\Logging\LoggingClient for other authentication options and further specific connection and setup.

Google\Cloud\Logging\Logger options

Please read the documentation for the Google\Cloud\Logging\Logger setup via Google\Cloud\Logging\LoggingClient for specific details about these options.

This set of options will allow you to set the default resource type and it's related labels that apply to all the logs. Please read Method: monitoredResourceDescriptors.list and do the "Try this API" to get a full list of the specific labels per resource.

Google\Cloud\Logging\Entry options

Please read the documentation for the Google\Cloud\Logging\Entry setup via Google\Cloud\Logging\Logger for specific details about these options.

By default, you can add Stackdriver specific log entry options by adding these wrapped in the stackdriver-key inside the context array. Very useful to add log entry specific labels for instance.

$context['stackdriver'] = [
    // stackdriver related entry options
];

If you need to, you can override this key name by setting $entryOptionsWrapper to your own value (string) when using StackdriverHandler::__construct.

It is also possible to set path to credentials and project id via the global constant.

define('GOOGLE_APPLICATION_CREDENTIALS', '/path/to/service-account-key-file.json'); 
define('GOOGLE_CLOUD_PROJECT', 'eg-my-project-id-148223');

Pick your framework for some specific setup

Vanilla usage

use Monolog\Logger;
use CodeInternetApplications\MonologStackdriver\StackdriverHandler;

// ( ... )

// GCP Project ID
$projectId = 'eg-my-project-id-148223';

// See Google\Cloud\Logging\LoggingClient::__construct
$loggingClientOptions = [
    'keyFilePath' => '/path/to/service-account-key-file.json'
];

// init handler
$stackdriverHandler = new StackdriverHandler(
    $projectId,
    $loggingClientOptions
);

// init logger with StackdriverHandler
$logger = new Logger('stackdriver', [$stackdriverHandler]);

// basic info log with contextual data
$logger->info('New order', ['orderId' => 1001]);
// ( ... )

// add specific log entry options, eg labels
$context = ['orderId' => 1001];

// add a 'stackdriver' entry to the context to append
// log entry specific options
$context['stackdriver'] = [
    'labels' => [
        'action' => 'paid'
    ]
];
$logger->info('Order update', $context);
// ( ... )

// add specific log entry options, eg labels and operation
$context = ['orderId' => 1001];
$context['stackdriver'] = [
    'labels' => [
        'order' => 'draft'
    ],
    'operation' => [
        'id' => 'order-1001',
        'first' => true,
        'last' => false
    ]
];
$logger->info('Order update', $context);

// update both label and operation
$context['stackdriver'] = [
    'labels' => [
        'order' => 'paid'
    ],
    'operation' => [
        'id' => 'order-1001',
        'first' => false,
        'last' => false
    ]
];
$logger->info('Order update', $context);

// update both label and operation again
$context['stackdriver'] = [
    'labels' => [
        'order' => 'fulfilled'
    ],
    'operation' => [
        'id' => 'order-1001',
        'first' => false,
        'last' => true
    ]
];
$logger->info('Order update', $context);

beyounglabs/monolog-stackdriver 适用场景与选型建议

beyounglabs/monolog-stackdriver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.18k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 beyounglabs/monolog-stackdriver 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.18k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-11