在生产环境中为管理员调试 laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45159504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debug laravel on production for admin
提问by Gediminas
I can't find any proper way to turn on debug mode in Laravel 5.4
on production only for admin.
我找不到任何正确的方法来Laravel 5.4
为管理员打开生产中的调试模式。
I have an app, which I'm debugging on production all day, so I need debug mode which will be seen only for me.
我有一个应用程序,我整天都在调试生产,所以我需要只有我才能看到的调试模式。
Is it posible to set APP_DEBUG=true
, instead of APP_DEBUG=false
, which is in .env
- on the fly in production? Or any other ways?
是否可以设置APP_DEBUG=true
, 而不是APP_DEBUG=false
, 哪个.env
在生产中正在运行?还是有其他方式?
回答by Anar Bayramov
Technically its not possible Authenticationcomes way after laravelitself (especially app.php) defined so you cant write something like
从技术上讲,它不可能在Laravel本身(尤其是app.php)定义之后进行身份验证,因此您无法编写类似的内容
if (isAdmin) {
debug = true'
}
if (isAdmin) {
debug = true'
}
But what you can do is in config/app.php
you can define debug like this and put your ip (be sure you are not using it in staging/local because you debug would return false in those cases too)
但是您可以做的是,config/app.php
您可以像这样定义调试并放置您的 ip(确保您没有在暂存/本地使用它,因为在这些情况下您调试也会返回 false)
'debug' => env('APP_DEBUG', $_SERVER['REMOTE_ADDR'] == 'your.ip.address' ? true : false)
Remove APP_DEBUG
line from production .env
file. When there will be no value, it will be taken from this condition. Leave it on local
to set it as you wish.
APP_DEBUG
从生产.env
文件中删除行。当没有价值时,将从这个条件中取出。保留它以根据需要local
进行设置。
So if it is your ip debug will be true otherwise false.
因此,如果是您的 ip debug,则为 true,否则为 false。
But I would say most secure and elegant way would be
但我会说最安全和优雅的方式是
1) Store logs in an authenticated route. Each error you get will be shown under a specific route as in log file aswell. but still it wont be instant. You can actually use package like this one https://github.com/rap2hpoutre/laravel-log-viewer
1) 将日志存储在经过身份验证的路由中。您得到的每个错误都将显示在特定路径下,如日志文件中一样。但它仍然不会是即时的。您实际上可以使用这样的包 https://github.com/rap2hpoutre/laravel-log-viewer
2) Using a service as sentry and email each error yourself or use their own panel
2)使用服务作为哨兵并自己通过电子邮件发送每个错误或使用他们自己的面板