How can I redirect Output to STDOUT with Laravel Scheduler command?(如何使用Laravel Scheduler命令将输出重定向到STDOUT?)
本文介绍了如何使用Laravel Scheduler命令将输出重定向到STDOUT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将计划程序应用程序运行到Docker容器中。
通过Supervisor管理Laravel调度程序并将其执行到容器中(我通过http://veithen.github.io/2015/01/08/supervisord-redirecting-stdout.html管理输出重定向):
[supervisord]
nodaemon = true
loglevel = info
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
umask = 022
pidfile = /tmp/supervisord.pid,
logfile = /tmp/supervisord.log
[program:scheduler]
directory = /var/www
command = sh -c 'php artisan schedule:run && sleep 60'
autorestart = true
redirect_stderr = true
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0
已调整我的Kernel.php代码以将输出附加到stdout_logfile:
$fileCronLog = '/dev/stdout';
$schedule->command('test')->everyMinute()->appendOutputTo($fileCronLog);
测试命令只是将字符串转储到STDOUT。
如果我将$fileCronLog设置为本地存储文件 正确写入文件$filepath我的命令输出。 但使用 $fileCronLog=‘/dev/stdout’;我看不到我的日志。我还尝试进入容器查看此文件,但始终为空。
推荐答案
我可能找到了我自己问题的解决方案。 这就是资源: https://github.com/moby/moby/issues/19616
在Supervisor将运行的Dockerfile中添加以下行:
RUN ln -sf /proc/1/fd/1 /var/log/laravel-scheduler.log
然后在Laravel应用程序/控制台/Kernel.php中
$fileCronLog = '/var/log/laravel-scheduler.log';
$schedule->command('test')->everyMinute()->appendOutputTo($fileCronLog);
这就是不同之处:
/var/log/laravel-Scheduler.log不应是指向/proc/self/fd/1的符号链接,
但发送到/proc/1/fd/1。
"细微但非常显著的差异。"
这篇关于如何使用Laravel Scheduler命令将输出重定向到STDOUT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何使用Laravel Scheduler命令将输出重定向到STDOUT?
基础教程推荐
猜你喜欢
- php中的PDF导出 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php中的foreach复选框POST 2021-01-01
