hanschrome / rest-api-logs-client
PHP 库,用于连接 hanschrome/rest-api-logs 并添加客户端。
dev-master
2020-06-09 14:32 UTC
Requires
- php: ^7.4.6 || ^8.0
- ext-curl: *
- ext-json: *
This package is auto-updated.
Last update: 2024-09-13 07:15:07 UTC
README
此 API 客户端已创建,以便在外部数据库中注册日志 - https://github.com/hanschrome/rest-api-logs
安装
- composer require hanschrome/rest-api-logs-client
用法
<?php require_once 'vendor/autoload.php'; use RestApiLogsClient\Common\Client\RestApiLogsClient; use RestApiLogsClient\Common\Client\RestApiLogsClientFactory; use RestApiLogsClient\Common\Configuration\GenericRestApiLogsConfiguration; use RestApiLogsClient\Common\Log\GenericLog; /* Add configurations to Factory*/ $restApiLogsConfiguration = new GenericRestApiLogsConfiguration(); $restApiLogsConfiguration->setSsl(true); $restApiLogsConfiguration->setDomain('example.com'); $restApiLogsConfiguration->setPath('/'); RestApiLogsClientFactory::addConfiguration($restApiLogsConfiguration); /* Recover the belonged RestApiLogsClient */ /** @var RestApiLogsClient $restApiLogsClient */ $restApiLogsClient = RestApiLogsClientFactory::get(); $genericLog = new GenericLog(); $genericLog->setApplication('TESTING_INDEX_APP'); $genericLog->setLevel(GenericLog::DEBUG_LEVEL); $genericLog->setEnvironment('dev'); $genericLog->setScope('TEST_INDEX_PHP'); $genericLog->setFilename(__FILE__); $genericLog->setLine(0); // __LINE__ or $exception $genericLog->setDebugBackTrace(debug_backtrace()); // or $exception get trace $genericLog->setSession('PHPSESSION=1238E89RJ2398R2938RJ2389RJ'); $genericLog->setClient(['Content-Type: application/json']); // user-agent... $genericLog->setException('Exception'); $genericLog->setError('TESTING'); $genericLog->setMessage('This is a testing log'); $genericLog->setVars(['key' => 'value']); $genericLog->setEventTrace([ 'required packages', 'Configured client', 'Instanciate generic log' ]); $genericLog->setObservations('It is a test'); /* Send log */ $restApiLogsClient->log($genericLog);