axel-kummer / logbook-php
PSR 兼容的日志记录器,用于将 PHP 应用的日志发送到日志服务器和客户端。
v0.2.1
2020-04-28 14:18 UTC
Requires
- guzzlehttp/guzzle: ^6.3
- psr/log: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6.4
This package is auto-updated.
Last update: 2024-09-29 00:21:56 UTC
README
本包提供了一个 PSR 兼容的 Logger,用于将日志发送到日志服务器和客户端,https://github.com/alexgunkel/logbook。Logger 提供了 Logger 本身以及一些适配器,用于以多种方式发送日志。
安装
您可以通过 git 或 composer 安装 logbook 的 PHP 组件。两种方法都需要 composer 来安装必要的依赖。
从 GitHub
## Cloning git repo
git clone https://github.com/axel-kummer/logbook-php.git /path/to/checkout
## cd in to path
cd /path/to/checkout
## Install dependencies
composer install --no-dev
从 Packagist
composer require axel-kummer/logbook-php
使用方法
基本使用
首先,您需要设置请求实例,该实例用于发送日志。
//Make a request instance
$request = \AxelKummer\LogBook\LoggerUtility::setupRequest(
\AxelKummer\LogBook\Request\HttpRequest::class,
'MyApplication',
'myhost'
8080
);
您还可以为请求内的所有日志添加一个唯一的请求标识符。
$request->setRequestId(\AxelKummer\LogBook\LoggerUtility::getRequestId('Prefix))
完成这些后,您可以简单地创建一个 Logger,它将注入请求对象。
//get a logger with injected request instance
$logger = \AxelKummer\LogBook\LoggerUtility::getLogger('MyLogger');
//Use the logger to send messages to the logbook server
$logger->info('My info mesage');
您可以实现并使用自己的请求类。您的类必须扩展 \AxelKummer\LogBook\Request\AbstractRequest 并实现 sendLog 和 getUrl 方法。