logdash/php-sdk
Composer 安装命令:
composer require logdash/php-sdk
包简介
Modern observability platform SDK for PHP
README 文档
README
Official PHP SDK for Logdash.io - Zero-configuration observability platform designed for developers working on side projects and prototypes.
Why Logdash?
Most observability solutions feel overwhelming for small projects and prototypes. Logdash provides instant logging and real-time metrics without complex configurations. Just add the SDK and start monitoring your application immediately.
Key Features
- 🚀 Zero Configuration: Start logging and tracking metrics in seconds
- 📊 Real-time Dashboard: Cloud-hosted interface with live data updates
- 📝 Structured Logging: Multiple log levels with rich context support
- 📈 Custom Metrics: Track counters, gauges, and business metrics effortlessly
- ⚡ Asynchronous: Non-blocking operations with automatic resource management
- 🛡️ Production Ready: Built with enterprise-grade patterns and error handling
- 🔧 Framework Agnostic: Works with Laravel, Symfony, or standalone PHP apps
- 🐘 PHP 8.1+ Compatible: Supports PHP 8.1, 8.2, 8.3, and all newer versions
Pre-requisites
Setup your free project in less than 2 minutes at logdash.io
Installation
Composer
composer require logdash/php-sdk
Quick Start
Basic Logging (Local Only)
<?php require_once 'vendor/autoload.php'; use Logdash\Logdash; // Create Logdash instance without API key for local logging only $logdash = Logdash::create(); $logger = $logdash->logger(); // Log different levels $logger->error('This is an error message'); $logger->warn('This is a warning message'); $logger->info('This is an info message'); $logger->debug('This is a debug message');
Cloud Logging & Metrics
<?php require_once 'vendor/autoload.php'; use Logdash\Logdash; // Create Logdash instance with API key for cloud sync $logdash = Logdash::create([ 'apiKey' => 'your-api-key-here', 'host' => 'https://api.logdash.io', // Optional, defaults to this 'verbose' => true // Optional, for debugging ]); $logger = $logdash->logger(); $metrics = $logdash->metrics(); // Logging with cloud sync $logger->error('Application error occurred'); $logger->info('User logged in successfully'); // Custom metrics $metrics->set('active_users', 150); $metrics->mutate('login_count', 1); // Increment by 1 $metrics->mutate('error_count', -1); // Decrement by 1
Framework Integration
Laravel
// In your AppServiceProvider or custom service provider use Logdash\Logdash; public function register() { $this->app->singleton('logdash', function ($app) { return Logdash::create([ 'apiKey' => config('services.logdash.api_key'), 'verbose' => config('app.debug') ]); }); } // Usage in controllers/services public function someMethod() { $logdash = app('logdash'); $logdash->logger()->info('Operation completed'); $logdash->metrics()->set('operation_count', 42); }
Symfony
// In your services.yaml services: logdash: class: Logdash\Logdash factory: ['Logdash\Logdash', 'create'] arguments: - apiKey: '%env(LOGDASH_API_KEY)%' verbose: '%kernel.debug%' // Usage in controllers/services public function someAction(Logdash $logdash) { $logdash->logger()->info('Action executed'); $logdash->metrics()->mutate('action_count', 1); }
API Reference
Logdash
Logdash::create(array $params = []): Logdash
Creates a new Logdash instance.
Parameters:
apiKey(string, optional): Your Logdash API key. If not provided, only local logging will workhost(string, optional): Logdash API host. Defaults tohttps://api.logdash.ioverbose(bool, optional): Enable verbose internal logging. Defaults tofalse
Logger
The logger provides methods for different log levels:
error(...$data): Log error level messageswarn(...$data): Log warning level messagesinfo(...$data): Log info level messageslog(...$data): Alias for info levelhttp(...$data): Log HTTP-related messagesverbose(...$data): Log verbose messagesdebug(...$data): Log debug messagessilly(...$data): Log silly level messages
Metrics
set(string $name, float $value): void
Set a metric to a specific value.
$metrics->set('cpu_usage', 45.2); $metrics->set('memory_usage', 1024);
mutate(string $name, float $value): void
Change a metric by the specified amount (can be positive or negative).
$metrics->mutate('request_count', 1); // Increment $metrics->mutate('error_count', -1); // Decrement $metrics->mutate('temperature', 2.5); // Increase by 2.5
Log Levels
The SDK supports the following log levels (in order of severity):
- ERROR: Error conditions
- WARN: Warning conditions
- INFO: Informational messages
- HTTP: HTTP request/response logs
- VERBOSE: Verbose informational messages
- DEBUG: Debug-level messages
- SILLY: Very detailed debug information
Configuration
Environment Variables
You can use environment variables for configuration:
LOGDASH_API_KEY=your-api-key-here LOGDASH_HOST=https://api.logdash.io LOGDASH_VERBOSE=true
$logdash = Logdash::create([ 'apiKey' => $_ENV['LOGDASH_API_KEY'] ?? '', 'host' => $_ENV['LOGDASH_HOST'] ?? 'https://api.logdash.io', 'verbose' => filter_var($_ENV['LOGDASH_VERBOSE'] ?? false, FILTER_VALIDATE_BOOLEAN) ]);
Error Handling
The SDK is designed to be non-blocking and fail silently in production. If there are issues with the API connection:
- Local logging will continue to work
- API errors are logged internally when verbose mode is enabled
- Your application will not be affected by Logdash connectivity issues
Requirements
- PHP 8.1 or higher
- Guzzle HTTP client (automatically installed via Composer)
Development
# Install dependencies composer install # Run tests composer test # Run static analysis composer phpstan # Check code style composer cs # Fix code style composer cbf
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- 📧 Email: support@logdash.io
- 🌐 Website: logdash.io
- 📚 Documentation: docs.logdash.io
- 🐛 Issues: GitHub Issues
logdash/php-sdk 适用场景与选型建议
logdash/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.64k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「monitoring」 「Metrics」 「tracing」 「observability」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 logdash/php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 logdash/php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 logdash/php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
A Zend Framework module that sets up Monolog for logging in applications.
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Statsd (Object Oriented) client library for PHP
Asynchronous Sentry for Symfony - Fire and forget
统计信息
- 总下载量: 2.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-27