ahmedels/visitlog
Composer 安装命令:
composer require ahmedels/visitlog
包简介
Laravel package to log visitor information into database.
README 文档
README
Introduction
VisitLog is a simple Laravel 5 package that can be used to log visitor information and save it into database.
Features
- Other than basic log such as IP, Browser and OS, it can also log Location information.
- Allows to log both unique and non-unique visits based on IP.
- Allows to cache the visits based on IP.
- Allows to log authenticated user info.
- Provides log viewer page out of box.
- Provides basic http authentication for app users.
- Ability to ban users by their IP
Note: VisitLog cannot detect same user/IP coming from some anonymizer so it cannot differentiate that.
Screenshot
Note: Info in above screenshot is fake.
Requirements
- PHP >= 5.5.9
- Laravel 5
Installation
Install via composer
composer require sarfraznawaz2005/visitlog
For Laravel < 5.5:
Add Service Provider to config/app.php in providers section
Sarfraznawaz2005\VisitLog\VisitLogServiceProvider::class,
Add Facade to config/app.php in aliases section
'VisitLog' => Sarfraznawaz2005\VisitLog\Facades\VisitLog::class,
Run php artisan vendor:publish to publish package's config and migration file. You should now have config/visitlog.php file published. It will also publish migration file in database/migrations folder.
Run php artisan migrate to create visitlogs table in your database.
Config Options
route: Route where visit log will be available.iptolocation: By default, only IP, Browser and OS info is logged. However if you set this option totrue, it will also log Location info through https://ipstack.com/ service. Note: You will need to create account there and get your access key and specify that in visitlog config file.cache: Ifiptolocationis set totrue, this option can be used to cache the results instead of requesting Location info each time from https://ipstack.com/.unique: Iftrue, it will only log unique visits based on IP address. Iffalse, it will log each visit even from same IP.log_user: Iftrue, it will also log authenticated user info.user_name_fields: Iflog_useristrue, this option can be used to specify name fields of user from your Users table in database.visitlog_page: Iftrue, a default log viewer page can be viewed athttp//yourapp.com/your_routeto see all the logs. Hereyour_routeis the first option above.http_authentication: Ifvisitlog_pageistrue, this option can be used to show visit log page to only authenticated app users by asking them email and password via basic http authentication.
Saving Log Info
To save logs, just call save method of VisitLog facade:
VisitLog::save();
Tip: If you want to save only unique logs based on IP, login or post-login page is good place to use the save method on because generally login page isn't visited again after user is authenticated. If you also want to save authenticated user, calling save method inside login post method seems to be good idea.
If however, you have set unique option to false and want to log all visits, calling save method in common location is good idea like base controller of your app.
Viewing Log Info
If config option visitlog_page is set to true, you can view all visit logs by browsing to http//yourapp.com/your_route.
Note: If you don't want to allow visitlog page to be publicly seen, set the option visitlog_page to false and now http//yourapp.com/your_route will result in 404 error.
In this case, you can still show log info in some authenticated area of your app by using all method of VisitLog facade: $visitLogs = VisitLog::all(); and it will give you Collection that you can iterate over and show in your own view file.
Credits
License
This code is published under the MIT License. This means you can do almost anything with it, as long as the copyright notice and the accompanying license file is left intact.
ahmedels/visitlog 适用场景与选型建议
ahmedels/visitlog 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「laravel」 「visitor」 「IP」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ahmedels/visitlog 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ahmedels/visitlog 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ahmedels/visitlog 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
Pacote simplificado para persistência de logs
Collection of tools to use the full power of the Enyalius framework
Tracker package for Laravel.
Allow users to post public messages on other users' profile pages
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-12-26