php-core/simple-telegram-log

A simple Telegram logging helper for PHP

dev-master 2024-12-14 05:06 UTC

This package is auto-updated.

Last update: 2024-12-14 05:06:35 UTC


README

A simple Telegram logging helper for PHP

Usage

composer require php-core/simple-telegram-log

Examples:

Using environment vars (short usage)

use PHPCore\SimpleTelegramLog\TGLog;

require_once dirname(__DIR__) . '/vendor/autoload.php';

TGLog::logMessage('Test message');

In code (flexible usage)

use PHPCore\SimpleTelegramLog\TGLog;

require_once dirname(__DIR__) . '/vendor/autoload.php';

TGLog::init(
    '123456:124334534534', // tg bot token
    -14943993494, // tg chat id
    false // debug mode
)->sendMessage('Test message');

Logging a PHP "Exception/Throwable"

use PHPCore\SimpleTelegramLog\TGLog;

require_once dirname(__DIR__).'/vendor/autoload.php';

TGLog::logException(new Exception('Test exception'));

Log request dump

use PHPCore\SimpleTelegramLog\TGLog;

require_once dirname(__DIR__).'/vendor/autoload.php';

TGLog::logRequestDump();

Debug log

use PHPCore\SimpleTelegramLog\TGLog;

require_once dirname(__DIR__).'/vendor/autoload.php';

TGLog::debugLogMessage('This message will only be logged if debug mode is on');

Using custom Bot API

use PHPCore\SimpleTelegramLog\TGLog;

require_once dirname(__DIR__).'/vendor/autoload.php';

TGLog::init(
    '123456:124334534534', // tg bot token
    -14943993494, // tg chat id
    false, // debug mode
    'https://tg-bot-api.php-core.com' // custom Bot API server url
)->sendMessage('Test message');

Using a cli program for HTTP requests (requires ability to run PHP's "exec" function and a cli program like "wget" installed)

use PHPCore\SimpleTelegramLog\TGLog;

require_once dirname(__DIR__).'/vendor/autoload.php';

TGLog::init(
    '123456:124334534534', // tg bot token
    -14943993494, // tg chat id
    false, // debug mode
    TGLog::API_BASE_URL, // custom Bot API server url
    'wget' // (or "curl") the cli program to use for the HTTP request
)->sendMessage('Test message');

Using a cli program with nohup for HTTP requests (requires ability to run PHP's "exec" function and "nohup" as well as a cli program like "wget" installed)

use PHPCore\SimpleTelegramLog\TGLog;

require_once dirname(__DIR__).'/vendor/autoload.php';

TGLog::init(
    '123456:124334534534', // tg bot token
    -14943993494, // tg chat id
    false, // debug mode
    TGLog::API_BASE_URL, // custom Bot API server url
    'exec nohup setsid wget' // (or "curl") the cli program to use for the HTTP request
)->sendMessage('Test message');

Optional Environment Variables for simple use: