[英]How can I access CakePHP log files on Heroku?
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.我已将 CakePHP 应用程序部署到 Heroku。CakePHP 默认将其日志写入
APP_ROOT/app/tmp/logs/error.log
和APP_ROOT/app/tmp/logs/debug.log
,但由于无法将 shell 写入到正在运行的 Heroku web dyno,我看不到这些文件的内容。
As I understand it, the heroku logs
command returns everything which has been dumped to STDERR
and STDOUT
.据我了解,
heroku logs
命令返回已转储到STDERR
和STDOUT
的所有内容。 If I'm right about that, is there a way to force CakePHP to send its logs to STDOUT
?如果我是对的,有没有办法强制 CakePHP 将其日志发送到
STDOUT
?
The Heroku PHP Buildpack tails the Apache and PHP log files as a background process as part of the dyno setup. Heroku PHP Buildpack将 Apache 和 PHP 日志文件作为后台进程作为 dyno 设置的一部分。 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 &
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 的细节,我在
heroku logs
中也没有看到任何 PHP 或 Apache 日志内容。
I think the following might work. 我认为以下可能会奏效。 Make sure you're using CakePHP 2.3.9.
确保您使用的是CakePHP 2.3.9。
App::uses('ConsoleOutput', 'Console');
CakeLog::config('default', array(
'engine' => 'ConsoleLog',
'stream' => new ConsoleOutput('php://stdout')
));
CakeLog::config('stdout', array(
'engine' => 'ConsoleLog',
'types' => array('notice', 'info'),
'stream' => new ConsoleOutput('php://stdout')
));
CakeLog::config('stderr', array(
'engine' => 'ConsoleLog',
'types' => array('emergency', 'alert', 'critical', 'error', 'warning', 'debug'),
'stream' => new ConsoleOutput('php://stderr')
));
CakeLog::config('debug', array(
'engine' => 'ConsoleLog',
'types' => array('notice', 'info', 'debug'),
'format' => 'debug %s: %s',
'stream' => new ConsoleOutput('php://stdout')
));
CakeLog::config('error', array(
'engine' => 'ConsoleLog',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'format' => 'error %s: %s',
'stream' => new ConsoleOutput('php://stderr')
));
From the Heroku documentation: https://devcenter.heroku.com/articles/php-logging#cakephp 从Heroku文档: https : //devcenter.heroku.com/articles/php-logging#cakephp
In your application configuration, instruct CakePHP to use the ConsoleLog engine for your logger setups: 在您的应用程序配置中,指示CakePHP使用ConsoleLog引擎进行记录器设置:
CakeLog::config('default', array(
'engine' => 'ConsoleLog',
));
You can then use the regular logging methods. 然后,您可以使用常规日志记录方法。
CakeLog::warning("Hello, this is a test message!");
Refer to the Logging section of the CakePHP manual for more information. 有关更多信息,请参阅CakePHP手册的“日志记录”部分。
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. 在最新版本的CakePHP(> = 3.6.0)中,
config/app.php
文件已预先配置为使用环境变量覆盖来进行库存debug
和error
日志。 These vars should contain a DSN-style string defining the same attributes you would normally place in your config/app.php
file. 这些变量应该包含一个DSN样式的字符串,用于定义您通常在
config/app.php
文件中放置的相同属性。
In the Heroku dashboard under Settings (or via the heroku
cli tool), you can add the following ENV vars: 在Settings (或通过
heroku
cli工具)下的Heroku仪表板中,您可以添加以下ENV变量:
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
The above two lines replicate the stock CakePHP logging, but redirect all output to the console instead of files. 以上两行复制了CakePHP日志库存,但是将所有输出重定向到控制台而不是文件。
you can use: 'className' => 'Cake\Log\Engine\ConsoleLog'
你可以使用:
'className' => 'Cake\Log\Engine\ConsoleLog'
/**
* Configures logging options
*/
'Log' => [
'debug' => [
'className' => 'Cake\Log\Engine\ConsoleLog',
'path' => LOGS,
'file' => 'debug',
'levels' => ['notice', 'info', 'debug'],
'url' => env('LOG_DEBUG_URL', null),
],
'error' => [
'className' => 'Cake\Log\Engine\ConsoleLog',
'path' => LOGS,
'file' => 'error',
'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
'url' => env('LOG_ERROR_URL', null),
],
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.