consigliere / signal
本软件包最新版本(v1.1.0)没有可用的许可证信息。
v1.1.0
2019-07-09 22:16 UTC
Requires
- illuminate/contracts: 5.8.*
- illuminate/support: 5.8.*
- jenssegers/agent: ^2.4
- webpatser/laravel-uuid: ^3.0
This package is not auto-updated.
Last update: 2024-09-29 04:36:43 UTC
README
日志记录器提供了RFC 5424中定义的八个日志级别:紧急、警报、临界、错误、警告、通知、信息和调试。将消息传递到事件中,它将自动检测请求URL、请求方法、客户端IP、浏览器、浏览器版本、用户操作系统等,并将其保存到数据库中。通过在配置文件中更改配置设置,可以将日志数据发送到用户电子邮件。
安装
composer require consigliere/signal
迁移
php artisan vendor:publish --tag=migrations-signal php artisan migrate
发布配置
php artisan vendor:publish --tag=config-signal
基本
Signal - 使用 event
助手
event('signal.emergency', [$message]); event('signal.alert', [$message,]); event('signal.critical', [$message]); event('signal.error', [$message]); event('signal.warning', [$message]); event('signal.notice', [$message]); event('signal.info', [$message]); event('signal.debug', [$message]);
Signal - 使用 Event
Facade
use Illuminate\Support\Facades\Event; Event::dispatch('signal.emergency', [$message]); Event::dispatch('signal.alert', [$message]); Event::dispatch('signal.critical', [$message]); Event::dispatch('signal.error', [$message]); Event::dispatch('signal.warning', [$message]); Event::dispatch('signal.notice', [$message]); Event::dispatch('signal.info', [$message]); Event::dispatch('signal.debug', [$message]);
事件包装器
在配置中,需要将 log.activity
和特定的日志控制设置为 true。
包装器
$this->fireLog('emergency', $message); $this->fireLog('alert', $message); $this->fireLog('critical', $message); $this->fireLog('error', $message); $this->fireLog('warning', $message); $this->fireLog('notice', $message); $this->fireLog('info', $message); $this->fireLog('debug', $message);
代码示例
use App\Components\Signal\Traits\Signal; class UserController extends Controller { use Signal; public function browse(Request $request): \Illuminate\Http\JsonResponse { $data = []; $option = $this->getOption(); $param = $this->getParam($this->type); try { $user = $this->userService->profile($data, $option, $param); } catch (\Exception $error) { # Provide $error instance of \Exception # Provide the uuid, upon empty, error uuid will be assigned automatically $this->fireLog('error', $error->getMessage(), ['error' => $error, 'uuid' => $this->euuid]); return $this->response($this->getErrorResponse($this->euuid, $error), 500); } return $this->response($user, 200); } }
Signal Api 响应错误报告示例
将日志数据发送到多个电子邮件接收者
确保应用程序可以通过在 .env
中提供正确的数据来发送电子邮件。
MAIL_DRIVER= MAIL_HOST= MAIL_PORT= MAIL_USERNAME= MAIL_PASSWORD= MAIL_ENCRYPTION=
在 .env
中将 LOG_ACTIVITY
和 SIGNAL_EMAIL_SENT
的值设置为 true
。提供用户电子邮件数据,其中将用逗号分隔。
LOG_ACTIVITY=true SIGNAL_EMAIL_SENT=true SIGNAL_EMAIL_SENT_TO=email1@example.com,email2@example.com,etc@example.com SIGNAL_USE_TABLE=signal_log MAIL_FROM_ADDRESS= MAIL_FROM_NAME=