Laravel Log Viewer ——一个基于 Bootstrap 搭建,适配 PC、平板和移动端的,可定制的日志查看后台

Laravel Log Viewer

简介

Laravel Log Viewer 提供了一个基于bootstrap搭建,适配PC、平板和移动端的日志查看后台,可自由配置访问路由、权限策略、中间件、导航链接,支持多语言和日志搜索、下载、删除

如果您觉得对您有用的话,别忘了给点个赞哦^_^ !
github:github.com/gouguoyin/laravel-log-viewer
gitee:gitee.com/gouguoyin/laravel-log-viewer

E3O59xEU5b.png!large7wYJg6tz0p.png!largeFMPZOzUU0L.png!large

安装配置

安装 larave-log-viewer

# 如果只想在开发环境安装请加上 --dev 
composer require gouguoyin/laravel-log-viewer

添加到服务提供者

config/app.phpproviders 数组中加入

Gouguoyin\LogViewer\LogViewerServiceProvider::class,
现在你已经可以通过访问你的域名/logs进入log-viewer后台,

自定义Log Viewer

运行php artisan vendor:publish --provider="Gouguoyin\LogViewer\LogViewerServiceProvider"会一次性生成

app/Providers/LogViewerServiceProvider.php 服务提供者文件

configs/log-viewer.php 配置文件

resources/lang/cn/log-viewer.php 中文翻译文件

resources/lang/en/log-viewer.php 英文翻译文件

resources/views/vendor/log-viewer 视图目录及视图文件

如果只想生成指定分类文件

只生成配置文件

php artisan vendor:publish --provider="Gouguoyin\LogViewer\LogViewerServiceProvider" --tag="log-viewer-config"

只生成服务提供者文件

php artisan vendor:publish --provider="Gouguoyin\LogViewer\LogViewerServiceProvider" --tag="log-viewer-provider"

只生成翻译文件

php artisan vendor:publish --provider="Gouguoyin\LogViewer\LogViewerServiceProvider" --tag="log-viewer-lang"

只生成视图文件

php artisan vendor:publish --provider="Gouguoyin\LogViewer\LogViewerServiceProvider" --tag="log-viewer-views"

通过修改以上文件即可在不修改扩展包的基础上进行自定义操作

权限验证

Log Viewer默认路由是 /logs, 默认情况下,只能在 local 环境下访问。在 app/Providers/LogViewerServiceProvider.php 文件中,有一个 gate 方法。这里授权控制 非本地 环境中的访问。 你可以根据需要随意修改此门面,以限制对 Log Viewer 的访问:

    /**
     * Register the log-viewer gate.
     *
     * This gate determines who can access log-viewer in non-local environments.
     *
     * @return void
     */
    protected function gate()
    {
        Gate::define('view-logs', function ($user) {
            return in_array($user->email, [
                //
            ]);
        });
    }

然后将 config/app.phpproviders 数组 中的 Gouguoyin\LogViewer\LogViewerServiceProvider::class 改成 Gouguoyin\LogViewer\LogViewerServiceProvider::class

Laravel会自动将 authenticated 用户注入到 gate 方法。如果你的应用程序通过其他方法(如IP限制)提供安全,那么用户可能不需要“登录”。因此,你需要将上面的 function ($user) 更改为 function ($user = null)以屏蔽身份验证。

配置说明

配置项 配置说明 可选值 默认值
web_route 配置访问路由 logs
web_middleware 配置访问中间件 [‘web’, ‘auth’]
web_navbar 配置后台右上角导航链接
locale_language 配置本地化语言 en:英文、cn:中文 cn
page_size_menu 配置表格每页显示条数下拉菜单 10, 20, 30, 50, 100
default_page_size 配置表格每页显示条数下拉菜单默认选项 20
fix_header 配置表格头字段是否固定 true、false true

更新日志

2020-02-24

  • 统一使用DIRECTORY_SEPARATOR常量替代/
  • 左侧日志文件支持模糊搜索

2020-02-20

  • 右上角新增下拉菜单
  • 支持自定义授权策略
  • 支持自定义视图
  • 支持自定义翻译文件
  • 支持自定义配置
本作品采用《CC 协议》,转载必须注明作者和本文链接
本帖由系统于 3年前 自动加精
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 11

请问可以查看堆栈吗

4年前 评论
普罗米修斯 (楼主) 4年前

mark一下 说不定用的到

4年前 评论
Explorer

Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead. Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead. Package zendframework/zend-escaper is abandoned, you should avoid using it. Use laminas/laminas-escaper instead.

4年前 评论
普罗米修斯 (楼主) 4年前

$ composer require gouguoyin/laravel-log-viewer

Content-Length mismatch, received 48887 bytes out of the expected 1484298 https://repo.packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date

3年前 评论
普罗米修斯 (楼主) 3年前

file

3年前 评论
普罗米修斯 (楼主) 3年前

然后将 config/app.php 的 providers 数组 中的 Gouguoyin\LogViewer\LogViewerServiceProvider::class 改成 Gouguoyin\LogViewer\LogViewerServiceProvider::class
这句是写错了吧

3年前 评论

我使用5.6版本报错 ,

Declaration of App\Providers\LogViewerServiceProvider::boot() should be compatible with Gouguoyin\LogViewer\LogViewerServiceProvider::boot(Gouguoyin\LogViewer\LogViewerService $logViewerService)

3年前 评论
zmj_phper 3年前

为什么我访问域名+logs 老是给我跳回首页

3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
文章
79
粉丝
16
喜欢
124
收藏
98
排名:679
访问:1.1 万
私信
所有博文
社区赞助商