我在让开发环境日志在 Symfony 1.4.8 中工作时遇到问题。同时,产品环境中的日志可以在相同的设置下完美运行。我不确定我的开发环境有什么问题。
想法是使用以下代码在操作和模板文件中记录消息:
sfContext::getInstance()->getLogger()->err('Error Message Here!!!');
但是,开发环境下的frontend_dev.log中并没有出现错误信息。为了启用日志记录,我修改了settings.yml和factorys.yml;我清除了 symfony 缓存和日志。由于某些奇怪的原因,在我清除日志(删除旧日志)后,symfony 没有在开发环境中生成新的 frontend_dev.log 。另一方面,在 prod 环境中,symfony 在执行清除日志命令后生成了一个空白的 frontend_prod.log。我不确定是什么导致了这个问题,以及这是否与日志记录在开发环境中无法工作有关。
这是我的settings.yml和factorys.yml中的设置
settings.yml:
prod:
.settings:
no_script_name: true
logging_enabled: true
cache: false
etag: false
dev:
.settings:
error_reporting: <?php echo (E_ALL | E_STRICT)."\n" ?>
logging_enabled: true
web_debug: true
cache: false
no_script_name: false
etag: false
factories.yml:
prod:
# logger:
# class: sfNoLogger
# param:
# level: err
# loggers: ~
logger:
class: sfAggregateLogger
param:
level: err
loggers:
sf_web_debug:
class: sfWebDebugLogger
param:
level: debug
condition: %SF_WEB_DEBUG%
xdebug_logging: true
web_debug_class: sfWebDebug
sf_file_debug:
class: sfFileLogger
param:
level: debug
file: %SF_LOG_DIR%/%SF_APP%_%SF_ENVIRONMENT%.log
dev:
mailer:
param:
delivery_strategy: none
logger:
class: sfAggregateLogger
param:
level: debug
loggers:
sf_web_debug:
class: sfWebDebugLogger
param:
level: debug
condition: %SF_WEB_DEBUG%
xdebug_logging: true
web_debug_class: sfWebDebug
sf_file_debug:
class: sfFileLogger
param:
level: debug
file: %SF_LOG_DIR%/%SF_APP%_%SF_ENVIRONMENT%.log
请让我知道我做错了什么。谢谢你。
更新:
我还尝试在 actions.class.php 中调用以下内容
$this->logMessage('ErrorMessageHere', 'err');
同样的结果,我在生产环境中收到错误消息,但在开发环境中没有收到错误消息。
我还尝试通过调用重置权限
php symfony project:permission
>> chmod 777 /var/www/ac2/web/uploads
>> chmod 777 /var/www/ac2/cache
>> chmod 777 /var/www/ac2/log
>> chmod 777 /var/www/ac2/symfony
>> chmod 777 /var/www/ac2/cache/frontend
......
drwxrwxrwx 2 www-data www-data 4096 2011-11-16 11:51 log
没有出现错误,看起来日志文件夹具有正确的权限。同样的事情发生了,在开发环境中symfony没有创建日志文件frontend_dev.log,但是在prod模式下清除日志后,创建了一个空白的frontend_prod.log。
这是我的frontend_dev.php:
<?php
// this check prevents access to debug front controllers that are deployed by accident to production servers.
// feel free to remove this, extend it or make something more sophisticated.
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1', '192.168.1.55')))
{
die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
sfContext::createInstance($configuration)->dispatch();
更新2:
我刚刚在开发和生产环境中的日志中发现了一些有趣的东西。
在我的 symfony 项目中,应用程序中有许多模块,我一直在操作和模板下的 2 个模块中测试消息日志记录。然而,今天我注意到一个有趣的事件,当我在其他模块中测试时,开发环境产生了错误消息,而生产环境却没有。如果我将错误日志插入 4-5 个模块,则某些日志将出现在 frontend_dev.log 中,其他日志将出现在 frontend_prod.log 中。我尝试清除缓存和清除日志;尽管如此,相同的模块会在 frontend_dev.log 中产生错误,其他模块也会在 frontend_prod.log 中产生错误
例如:我在 /web/index.php 中启用了 prod 环境,并将以下错误日志代码插入到 4 个不同模块中的 4 个不同的 actions.class.php 中
$this->logMessage('errortest1', 'err');
$this->logMessage('errortest2', 'err');
$this->logMessage('errortest3', 'err');
$this->logMessage('errortest4', 'err');
如果我在生产环境中同时启用开发和生产错误日志记录。 errortest1和errortest2将出现在frontend_dev.log中,errortest3和errortest4将出现在frontend_prod.log中 如果我只在产品环境中启用产品错误日志记录。 frontend_dev.log 将为空,errortest3 和 errortest4 将出现在 frontend_prod.log 中 如果我只在开发环境中启用开发错误日志记录。 errortest1和errortest2将出现在frontend_dev.log中,而frontend_prod.log将为空
所以我不确定发生了什么事,我的 symfony 项目是否已损坏?
可能“ “在行尾会干扰你的代码吗?
尝试在线条之间留出间隙。
dev:
.settings:
error_reporting: <?php echo (E_ALL | E_STRICT); ?>
logging_enabled: true
web_debug: true