PHPackages                             devly/telegram-logger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. devly/telegram-logger

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

devly/telegram-logger
=====================

A Telegram-based logging system for PHP applications

062PHP

Since Nov 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/valenjeb/telegram-logger)[ Packagist](https://packagist.org/packages/devly/telegram-logger)[ RSS](/packages/devly-telegram-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Telegram Logger for PHP
=======================

[](#telegram-logger-for-php)

A PHP library for sending log messages to Telegram channels/chats.

Installation
------------

[](#installation)

Install via Composer:

```
composer require devly/telegram-logger
```

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- A Telegram Bot Token (get it from [@BotFather](https://t.me/botfather))
- A Chat ID where messages will be sent

Quick Start
-----------

[](#quick-start)

```
use Devly\TelegramLogger\Logger;

$logger = new Logger('YOUR_BOT_TOKEN', 'YOUR_CHAT_ID');

// Send a simple log message
$logger->info('Application started successfully');
$logger->warning('Low disk space warning');
$logger->error('Database connection failed');
$logger->exception(new Exception('Something went wrong!', 500));
```

Features
--------

[](#features)

- Multiple log levels (info, warning, error)
- Support for different parse modes (HTML, Markdown, MarkdownV2)
- Automatic file and URL detection
- Custom chat ID support for each message
- Exception logging support

Usage Examples
--------------

[](#usage-examples)

### Different Parse Modes

[](#different-parse-modes)

```
// HTML formatting
$logger->setParseMode(Logger::PARSE_MODE_HTML);
$logger->info('Bold message with HTML formatting');
// Markdown formatting
$logger->setParseMode(Logger::PARSE_MODE_MARKDOWN);
$logger->info('**Bold message** with *Markdown formatting*');
// MarkdownV2 formatting
$logger->setParseMode(Logger::PARSE_MODE_MARKDOWNV2);
$logger->info('*Bold message* with *MarkdownV2 formatting*');
```

### Exception Logging

[](#exception-logging)

```
try {
    // Some code that might throw an exception
    throw new Exception('Something went wrong!', 500);
} catch (Throwable $e) {
    // Log the exception with additional context
    $logger->exception($e, null, null, [
        'user_id' => 123,
        'action' => 'user_registration',
        'data' => ['email' => 'user@example.com']
    ]);
}
```

The exception logger will automatically include:

- Exception message
- Exception type/class
- Error code
- File and line where the error occurred
- Full stack trace
- Any additional context provided

### Custom Chat ID

[](#custom-chat-id)

```
$logger->info('This message will be sent to the custom chat ID', 'YOUR_CHAT_ID');
```

### System Monitoring Example

[](#system-monitoring-example)

```
$logger->info(sprintf(
    "Server Status Report:\n" .
    "Memory Usage: %s\n" .
    "CPU Load: %s\n" .
    "Disk Space: %s",
    memory_get_usage(true),
    sys_getloadavg()[0],
    disk_free_space('/')
));
```

### Cron Job Monitoring

[](#cron-job-monitoring)

```
function logCronJob(Logger $logger, string $jobName, callable $job): void
{
    $startTime = microtime(true);
    $logger->info(sprintf('Starting cron job: %s', $jobName));
    try {
        $job();
        $duration = round(microtime(true) - $startTime, 2);
        $logger->info(
            sprintf('Completed cron job: %s (Duration: %s seconds)', $jobName, $duration)
        );
    } catch (Throwable $e) {
        $logger->error(
            sprintf('Failed cron job: %s', $jobName) .
            "\nError: " . $e->getMessage()
        );
    }
}
```

API Reference
-------------

[](#api-reference)

### Constructor

[](#constructor)

```
public function construct(
    string $botToken,
    string $chatId,
    string $parseMode = self::PARSE_MODE_HTML
)
```

### Methods

[](#methods)

#### Log Levels

[](#log-levels)

```
public function info(string $message, ?string $chatId = null, ?string $parseMode = null): bool
public function warning(string $message, ?string $chatId = null, ?string $parseMode = null): bool
public function error(string $message, ?string $chatId = null, ?string $parseMode = null): bool
public function exception(Throwable $exception, ?string $chatId = null, ?string $parseMode = null, ?array $context = null): bool
```

#### Parse Mode

[](#parse-mode)

```
public function setParseMode(string $parseMode): void
```

Available parse modes:

- `Logger::PARSE_MODE_HTML`
- `Logger::PARSE_MODE_MARKDOWN`
- `Logger::PARSE_MODE_MARKDOWNV2`

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cf24c8df7402aa53fe166d2822d2470850417cb2745e8957b88c282e593ca7ec?d=identicon)[devly](/maintainers/devly)

---

Top Contributors

[![valenjeb](https://avatars.githubusercontent.com/u/7081274?v=4)](https://github.com/valenjeb "valenjeb (1 commits)")

### Embed Badge

![Health badge](/badges/devly-telegram-logger/health.svg)

```
[![Health](https://phpackages.com/badges/devly-telegram-logger/health.svg)](https://phpackages.com/packages/devly-telegram-logger)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[ekino/newrelic-bundle

Integrate New Relic into Symfony2

28111.2M8](/packages/ekino-newrelic-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
