【问题标题】:Symfony 1.4 dev logging not workingSymfony 1.4 开发日志不工作
【发布时间】:2011-12-30 21:56:43
【问题描述】:

我无法让开发环境日志在 Symfony 1.4.8 中工作。同时,在 prod 环境中的日志可以在相同的设置下完美运行。我不确定我的开发环境有什么问题。

想法是使用以下代码在动作和模板文件中记录消息:

    sfContext::getInstance()->getLogger()->err('Error Message Here!!!');

但是,在开发环境中,frontend_dev.log 中没有出现错误信息。为了启用日志记录,我修改了 settings.yml 和 factory.yml;我清除了 symfony 缓存和日志。出于某种奇怪的原因,在我清除日志(删除旧日志)后,symfony 没有在开发环境中生成新的 frontend_dev.log。另一方面,在 prod 环境中,symfony 在执行 clear logs 命令后生成了一个空白的 frontend_prod.log。我不确定是什么原因造成的,以及这是否与无法在开发环境中工作的日志记录有关。

这是我的 settings.yml 和 factory.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');

同样的结果,我在 prod 环境中得到了错误消息,但在 dev 环境中没有。

我也尝试通过调用来重置权限

    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

没有出现错误,看起来日志文件夹具有正确的权限。同样的事情,在dev环境下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 项目中,应用程序中有许多模块,我一直在 Actions 和 Templates 下的 2 个模块中测试消息记录。但是,今天我注意到一个有趣的事件,当我在其他模块中进行测试时,开发环境产生了错误消息而 prod 没有。如果我将错误日志插入 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');

如果我在 prod 环境中同时启用 dev 和 prod 错误日志记录。 errortest1 和 errortest2 将出现在 frontend_dev.log 中,errortest3 和 errortest4 将出现在 frontend_prod.log 中 如果我只在 prod 环境中启用 prod 错误日志记录。 frontend_dev.log 将为空并且 errortest3 和 errortest4 将出现在 frontend_prod.log 如果我只在开发环境中启用开发错误日志记录。 errortest1 和 errortest2 将出现在 frontend_dev.log 中,而 frontend_prod.log 将为空

所以我不确定发生了什么,我的 symfony 项目是否被损坏了?

【问题讨论】:

  • 我似乎无法找到任何错误。尝试检查您 /log 文件夹的权限
  • 附带说明,在您的操作中使用它来记录消息:$this->logMessage("Error!", "err")。不要在动作中重新实例化 sfContext 单例类。
  • 感谢大家的帮助。我通过调用“php symfony project:permission”来重置项目权限。我试过 "$this->logMessage('ErrorMessage', 'err'); 同样的结果,我能够在 prod 环境中得到错误消息,但在 dev 环境中没有。我会研究 dev_debug 和 prod_debug 规则,也许我在那里遗漏了一些东西。
  • 你能告诉我们你的 web 目录中的 frontend_dev.php 文件吗?
  • 添加了 frontend_dev.php 文件。感谢您调查问题。

标签: logging symfony1 environment


【解决方案1】:

行尾的“\n”可能会干扰您的代码吗?

试着在两行之间留一个空隙。

dev:
  .settings:
    error_reporting:        <?php echo (E_ALL | E_STRICT); ?>

    logging_enabled:        true
    web_debug:              true

【讨论】:

    猜你喜欢
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多