如何访问 Heroku 上的 CakePHP 日志文件?

How can I access CakePHP log files on Heroku?(如何访问 Heroku 上的 CakePHP 日志文件?)
本文介绍了如何访问 Heroku 上的 CakePHP 日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已将 CakePHP 应用程序部署到 Heroku.CakePHP 默认将其日志写入 APP_ROOT/app/tmp/logs/error.logAPP_ROOT/app/tmp/logs/debug.log 但因为没有办法获取正在运行的 Heroku Web dyno 的 shell,我看不到这些文件的内容.

I've deployed a CakePHP application to Heroku. CakePHP writes its logs in APP_ROOT/app/tmp/logs/error.log and APP_ROOT/app/tmp/logs/debug.log by default but since there's no way to get a shell to a running Heroku web dyno, I can't see the content of those files.

据我所知,heroku logs 命令返回已转储到 STDERRSTDOUT 的所有内容.如果我是对的,有没有办法强制 CakePHP 将其日志发送到 STDOUT?

As I understand it, the heroku logs command returns everything which has been dumped to STDERR and STDOUT. If I'm right about that, is there a way to force CakePHP to send its logs to STDOUT?

Heroku PHP Buildpack 将 Apache 和 PHP 日志文件作为后台进程跟踪为dyno 设置的一部分.见下文.

The Heroku PHP Buildpack tails the Apache and PHP log files as a background process as part of the dyno setup. See below.

cat >>boot.sh <<EOF
for var in `env|cut -f1 -d=`; do
  echo "PassEnv $var" >> /app/apache/conf/httpd.conf;
done
touch /app/apache/logs/error_log
touch /app/apache/logs/access_log
tail -F /app/apache/logs/error_log &
tail -F /app/apache/logs/access_log &
export LD_LIBRARY_PATH=/app/php/ext
export PHP_INI_SCAN_DIR=/app/www
echo "Launching apache"
exec /app/apache/bin/httpd -DNO_DETACH
EOF

在该构建包的一个分支中,我在适当的位置添加了自己的行,然后将我的应用程序配置为使用我的自定义构建包.

In a fork of that build pack, I added in my own lines in the appropriate positions, then configured my app to use my custom build pack.

touch /app/www/tmp/logs/error.log
tail -F /app/www/app/tmp/logs/error.log &

但这没有用.事实上,撇开 CakePHP 的细节不谈,我在 heroku 日志 中也看不到任何 PHP 或 Apache 日志内容.

But this didn't work. In fact, setting aside CakePHP specifics, I don't see any PHP or Apache log contents in the heroku logs either.

推荐答案

在最新版本的 CakePHP (>= 3.6.0) 中,config/app.php 文件预先配置为对股票 debugerror 日志使用环境变量覆盖.这些变量应包含定义相同的 DSN 样式字符串您通常会放置在 config/app.php 文件中的属性.

In the latest versions of CakePHP (>= 3.6.0), the config/app.php file comes pre-configured to use an environment variable override for the stock debug and error logs. These vars should contain a DSN-style string defining the same attributes you would normally place in your config/app.php file.

设置(或通过heroku cli工具)下的Heroku仪表板中,您可以添加以下ENV变量:

In the Heroku dashboard under Settings (or via the heroku cli tool), you can add the following ENV vars:

LOG_DEBUG_URL = file:///?className=Cake%5CLog%5CEngine%5CConsoleLog&levels[]=notice&levels[]=info&levels[]=debug
LOG_ERROR_URL = file:///?className=Cake%5CLog%5CEngine%5CConsoleLog&levels[]=warning&levels[]=error&levels[]=critical&levels[]=alert&levels[]=emergency

以上两行复制了 CakePHP 的日志记录,但将所有输出重定向到控制台而不是文件.

The above two lines replicate the stock CakePHP logging, but redirect all output to the console instead of files.

这篇关于如何访问 Heroku 上的 CakePHP 日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)