承接 saasscaleup/laravel-stream-log 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

saasscaleup/laravel-stream-log

Composer 安装命令:

composer require saasscaleup/laravel-stream-log

包简介

Easily stream your Laravel application logs to the frontend in real-time using server-sent event (SSE)

README 文档

README

Main Window two

Easily stream your Laravel application logs to the frontend in real-time using server-sent event (SSE)

Youtube · Twitter · Facebook · Buy Me a Coffee

Latest Stable Version Total Downloads License

✨ Features

  • Easily stream your Backend events from your Controllers \ Events \ Models \ Etc... .
  • Easily stream your Logs (storage/logs/laravel.log).
  • Print Backend logs and events to Frontend browser console.log(data)

banner

Requirements

  • PHP >= 7
  • Laravel >= 5

Installation

Install composer package (dev)

Via Composer - Not recommended for production environment

$ composer require --dev saasscaleup/laravel-stream-log

For Laravel < 5.5

Add Service Provider to config/app.php in providers section

Saasscaleup\LSL\LSLServiceProvider::class,

Add Facade to config/app.php in aliases section

'LSL' => Saasscaleup\LSL\Facades\LSLFacade::class,

Publish package's config, migration and view files

Publish package's config, migration and view files by running below command:

$ php artisan vendor:publish --provider="Saasscaleup\LSL\LSLServiceProvider"

Run migration command

Run php artisan migrate to create stream_logs table.

$ php artisan migrate

Setup Laravel Stream Log -> LSL

Aadd this in your main view/layout (usually layout/app.blade.php) file:

@include('lsl::view')

Configuration

Configuration is done via environment variables or directly in the configuration file (config/lsl.php).

<?php

return [

    // enable or disable LSL
    'enabled' => env('LSL_ENABLED', true),

    // enable or disable laravel log listener 
    'log_enabled' => env('LSL_LOG_ENABLED', true),

    // log listener  for specific log type
    'log_type' => env('LSL_LOG_TYPE', 'info,error,warning,alert,critical,debug'), // Without space

    // log listener for specific word inside log messages
    'log_specific' => env('LSL_LOG_SPECIFIC', ''), // 'test' or 'foo' or 'bar' or leave empty '' to disable this feature

    // echo data loop in LSLController
    'interval' => env('LSL_INTERVAL', 1),

    // append logged user id in LSL response
    'append_user_id' => env('LSL_APPEND_USER_ID', true),

    // keep events log in database
    'keep_events_logs' => env('LSL_KEEP_EVENTS_LOGS', false),

    // Frontend pull invoke interval
    'server_event_retry' => env('LSL_SERVER_EVENT_RETRY', '2000'),

    // every 10 minutes cache expired, delete logs on next request
    'delete_log_interval' => env('LSL_DELETE_LOG_INTERVAL', 600), 

    /******* Frontend *******/

    // eanlbed console log on browser
    'js_console_log_enabled' => env('LSL_JS_CONSOLE_LOG_ENABLED', true),

     // js notification toast library
    'js_notification_library' => env('LSL_JS_NOTIFICATION_LIBRARY', 'noty'), // 'izitoast' or 'noty'

    // notification settings
    'js_position' => 'bottomRight', // topLeft, topCenter, topRight, center, bottomLeft, bottomCenter, bottomRight
    'js_timeout' => 5000, // false, 1000, 3000, 3500, etc. Delay for closing event in milliseconds (ms). Set 'false' for sticky notifications.
];

Usage

Syntax:

/**
* @param string $message : notification message
* @param string $type : alert, success, error, warning, info, debug, critical, etc...
* @param string $event : Type of event such as "EmailSent", "UserLoggedIn", etc
 */
LSLFacade::notify($message, $type = 'info', $event = 'stream')

To show popup notifications on the screen, in your controllers/event classes, you can do:

use Saasscaleup\LSL\Facades\LSLFacade;

public function myFunction()
{

    LSLFacade::notify('Invoke stream log via Facade 1');

    // Some code here

    LSLFacade::notify('Invoke stream log via Facade 2');

    // Some code here

    LSLFacade::notify('Invoke stream log via Facade 3');
    
    // or via helper
    stream_log('Invoke stream log via helper 1');
    stream_log('Invoke stream log via helper 2');     
    stream_log('Invoke stream log via helper 3');
}

Customizing Notification Library

By default, package uses noty for showing notifications.

You can switch to izitoast by updating config file config/lsl.php

 // js notification toast library
'js_notification_library' => env('LSL_JS_NOTIFICATION_LIBRARY', 'izitoast'), // 'izitoast' or 'noty'

You can also, customize this by modifying code in resources/views/vendor/lsl/view.blade.php file.

Customizing LSL Events

By default, pacakge uses stream event type for streaming response:

LSLFacade::notify($message, $type = 'info', $event = 'message')

Notice $event = 'stream'. You can customize this, let's say you want to use UserPurchase as SSE event type:

use Saasscaleup\LSL\Facades\LSLFacade;

public function myMethod()
{
    SSEFacade::notify('User purchase plan - step 1', 'info', 'UserPurchase');
    
    // or via helper
    stream_log('User purchase plan - step 1', 'info', 'UserPurchase');
}

Then you need to handle this in your view yourself like this:

<script>
var es = new EventSource("{{route('lsl-stream-log')}}");

es.addEventListener("UserPurchase", function (e) {
    var data = JSON.parse(e.data);
    alert(data.message);
}, false);

</script>

License

Please see the MIT for more information.

Support 🙏😃

If you Like the tutorial and you want to support my channel so I will keep releasing amzing content that will turn you to a desirable Developer with Amazing Cloud skills... I will realy appricite if you:

  1. Subscribe to our youtube
  2. Buy me A coffee ❤️

Thanks for your support :)

saasscaleup/laravel-stream-log 适用场景与选型建议

saasscaleup/laravel-stream-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 36, 最近一次更新时间为 2023 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「log」 「debug」 「event」 「notifications」 「server」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 saasscaleup/laravel-stream-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 saasscaleup/laravel-stream-log 我们能提供哪些服务?
定制开发 / 二次开发

基于 saasscaleup/laravel-stream-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 36
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 36
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-06