Skip to content

borzenkovdev/php-telemetry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telemetry - lightweight PHP Logging Library with Multi-Driver Support

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages