borzenkovdev/php-telemetry 问题修复 & 功能扩展

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

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

borzenkovdev/php-telemetry

最新稳定版本:1.0.0

Composer 安装命令:

composer require borzenkovdev/php-telemetry

包简介

This package offer a variety of features for meaningful logging.

关键字:

README 文档

README

Packagist Version Packagist PHP Version Support Packagist Downloads

A flexible and configurable logging library for PHP, supporting transactions with unique IDs, customizable date formats, and time zones. This library simplifies tracking logs with transaction IDs and performance timings and implements the PSR-3 specification.

Features

  • Supports logging messages with various log levels.
  • Provides unique transaction IDs for tracking grouped logs.
  • Customizable date and time formats.
  • Allows setting a custom time zone.
  • Supports PSR-3 log levels for compatibility.

Installation

Install the latest version with:

$ composer require borzenkovdev/php-telemetry

Usage

Basic Usage

<?php

use Telemetry\Telemetry;
use Telemetry\drivers\CliDriver;
use Psr\Log\LogLevel;

$telemetry = new Telemetry(new CliDriver());

// Set log level manually
$telemetry->log(LogLevel::INFO, 'Service started', ['origin' => 'http', 'customerId' => '123']);

// Quick methods for different log levels types
$telemetry->info('Info level log', ['user' => '123']);
$telemetry->debug('Debug level log', ['details' => 'Step 1 completed']);
$telemetry->error('Error level log', ['errorCode' => '404']);
$telemetry->critical('Critical level log', ['errorCode' => '500']);
$telemetry->alert('Alert level log', ['errorCode' => '500']);
$telemetry->emergency('Emergency level log', ['errorCode' => '500']);

Basic Usage with transaction

<?php

use Telemetry\Telemetry;
use Telemetry\drivers\CliDriver;
use Psr\Log\LogLevel;

$telemetry = new Telemetry(new CliDriver());

$telemetry->beginTransaction();
$telemetry->log(LogLevel::DEBUG, 'Processing order', ['step' => '1']);
$telemetry->log(LogLevel::WARNING, 'Slow response from DB', ['db' => 'orders']);
$telemetry->endTransaction();

For more examples, see the examples folder.

Configuring Date Format and Time Zone

You can set a custom date format and time zone using setDateFormat and setTimeZone.

$telemetry->setDateFormat('Y-m-d H:i:s');
$telemetry->setTimeZone('America/New_York');

This configuration will format timestamps according to the specified format and time zone.

Adding a Custom Driver

To add a custom driver, implement the DriverInterface and define the write method to handle log storage.

Example

<?php

namespace Telemetry\Drivers;

use Telemetry\DriverInterface;

class CustomDriver implements DriverInterface
{
    public function write(string $message): void
    {
        // Custom logic to store or display log message
    }
}

Usage

<?php

$customDriver = new CustomDriver();
$telemetry = new Telemetry($customDriver);
$telemetry->log(LogLevel::INFO, "Testing custom driver");

UML Diagram

UML Class Diagram

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固