mmdm/sim-logger 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mmdm/sim-logger

Composer 安装命令:

composer require mmdm/sim-logger

包简介

A simple yet nice logger library

README 文档

README

A library to log your activities

Install

composer

composer require mmdm/sim-logger

Or you can simply download zip file from github and extract it, then put file to your project library and use it like other libraries.

Just add line below to autoload files:

require_once 'path_to_library/autoloader.php';

and you are good to go.

How to use

// to instance a logger object
$logger = new Logger(new FileHandler($directory_to_store_logs));

// now use logger functions, for instance debug method
$logger->debug('this is a debug message');

Or instantiate Logger with other optional constructor parameters

Description

$logger = new Logger([$handler[, $format[, $date_format]]]);

$handler is a type of IHandler and an IHandler is an interface to extend logger for other kind of handlers and not just file handling.

Also you can set handler after initializing the logger with method handler(IHandler $handler).

To extend IHandler you must implement these functions

class CustomHandler implements IHandler
{
    /**
     * CunstomHandler constructor.
     */
    public function __construct()
    {
        // do initialize your needed things
    }

    /**
     * @return IHandler
     */
    public function init(): IHandler
    {
        // to whatever need for handler initialization
        
        return $this;
    }

    /**
     * @param string $message
     * @param array $data
     * @return bool
     */
    public function write(string $message, array $data = []): bool
    {
        // write $message with your log handler
        // $data have all parameters as key => value pairs
        
        // return true if write was OK or false if it wasn't
    }
}

$format is to format message that need to be written. Default value is {level}: {date} - {message}

$format_date is to format date of log. Default value is Y-m-d H:i:s.

Available functions

There are many functions to log your message. The order of importance of them are:

  • EMERGENCY - highest level priority

  • ALERT

  • CRITICAL

  • ERROR

  • WARNING

  • NOTICE

  • INFO

  • DEBUG - lowest level priority

// log emergency
$logger->emergency($message);

// log alert
$logger->alert($message);

// log critical
$logger->critical($message);

// log error
$logger->error($message);

// log warning
$logger->warning($message);

// log notice
$logger->notice($message);

// log info
$logger->info($message);

// log debug
$logger->debug($message);

// or you can use log function to log any level you want,
// including previous functions
$logger->log($message, LOGGER::DEBUG);
// or
$logger->log($message, 'custom level');

If you have additional data to log, then you should use extraParameters($parameter) method and modify logger format to show your parameter in log message with format($format) method.

$logger->extraParameters([
'other_parameter' => $valueOfParameter
])->format('{level} - {other_parameter} - {message}');

// now we can use log methods
$logger->log('a log message', 'custom level');

If you need to change date format, then you can use dateFormat($format) method

$logger->dateFormat('Y/m/d H:i');

If you want have a better experience with date, you should enter your timezone through setTimezone($timezone) method. Default timezone is environment default timezone.

The timezone will show with date for more information.

exp. 2020-07-25 09:46:19 (America/New_York)

$logger->setTimezone('America/New_York');

License

Under MIT license.

mmdm/sim-logger 适用场景与选型建议

mmdm/sim-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-25