承接 fei/logger-client 相关项目开发

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

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

fei/logger-client

Composer 安装命令:

composer require fei/logger-client

包简介

Client side logger

README 文档

README

GitHub licensecontinuousphpGitHub issues

Installation

Just add the following requirement to your composer.json file:

    "fei/logger-client": "^1.2.0"

Configuration

The logger client needs some options to work properly. The available options that can be passed to the __construct() or setOptions() methods are :

Option Description Type Possible Values Default
OPTION_BASEURL This is the server to which send the requests. string Any URL, including protocol but excluding path --
OPTION_FILTER Minimum notification level required for notifications to be actually sent. int Any Notification::LVL_* constant Notification::LVL_ERROR
OPTION_BACKTRACE Should backtrace be added to notifications before they are sent. bool true / false true
OPTION_LOGFILE File path and name where the Logger will store its own exceptions. string Any writeable file path /tmp/logger.log
OPTION_HEADER_AUTHORIZATION Api Key for authentification string Any string value ''

Notes: Logger is an alias of Fei\Service\Logger\Client\Logger Notification is an alias of Fei\Service\Logger\Entity\Notification

Usage

Initialization

A Logger client should always be initialized by a dependency injection component, since it requires at least one dependency, which is the transport. Moreover, the BASEURL parameter should also depends on environment.

// sample configuration for production environment
$logger = new Logger(array(
                            Logger::OPTION_BASEURL  => 'http://logger.flash-global.net',
                            Logger::OPTION_FILTER   => Notification::LVL_DEBUG,
                          )
                    );
// inject transport classes
$logger->setTransport(new BasicTransport());

// optionnal asynchronous transport, that will be automatically used to push notifications
//
// NOTE this transport requires a beanstalk queue able to listen to its requests
$pheanstalk = new Pheanstalk('localhost');
$asyncTransport = new BeanstalkProxyTransport;
$asyncTransport->setPheanstalk($pheanstalk);
$logger->setAsyncTransport($asyncTransport);

Pushing a simple notification

Once you have set up the Logger, you can start pushing notifications by calling the notify() method on the Logger:

$logger = $container->get('logger');

$logger->notify('Notification message'); // default level is Notification::LVL_INFO
$logger->notify('Debug message', array('level' => Notification::LVL_DEBUG));

While its possible to pass more than just the level using the second (array) parameter, it is recommended not to do so. If you want to pass more informations, like a context, please take a look at the following section.

Pushing a Notification instance

The more reliable way to push a notification is to instantiate it by yourself, and then send it through notify(), that will also accept Notification instances:

$logger = $container->get('logger');

$notification = new Notification(array('message' => 'Notification message'));
$notification
        ->setLevel(Notification::LVL_WARNING)
        ->setContext(array('key' => 'value')
        ;
        
$logger->notify($notification);

PSR-3 Adapter

PSR-3 describe an interface for logging purpose to ensure interoperability between systems.

For this end we provide the adapter Fei\Service\Logger\Client\Psr\PsrLoggerAdapter.

<?php

use Fei\Service\Logger\Client\Logger;
use Fei\Service\Logger\Client\Psr\PsrLoggerAdapter;

$logger = new Logger();

$psr = new PsrLoggerAdapter($logger);

$psr->error('This is a error message');

It's always possible to set category, namespace and other notification properties with log context:

<?php

use Fei\Service\Logger\Client\Logger;
use Fei\Service\Logger\Client\Psr\PsrLoggerAdapter;
use Fei\Service\Logger\Entity\Notification;

$logger = new Logger();

$psr = new PsrLoggerAdapter($logger);

$psr->error(
    'This is a error message',
    [
        'namespace' => '/my/app',
        'category' => Notification::TRACKING,
        'key1' => 'value1',
        'key2' => 'value2'
    ]
);

Manageable Notification properties are flag, namespace, user, server, command, origin, category and env. Another key of context will be set in Notification context.

fei/logger-client 适用场景与选型建议

fei/logger-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.91k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2018-03-14