5

I'm having trouble getting dev environment logs to work in Symfony 1.4.8. Meanwhile, logs in prod environment works perfectly with the same settings. I'm not sure what is wrong with my dev environment.

The ideas is to log messages in Action and Template files using the following code:

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

However, error message did not appear in frontend_dev.log in dev environment. To enable logging, I modified settings.yml and factories.yml; I cleared symfony cache and logs. For some odd reason, symfony did not generate a new frontend_dev.log in dev environment after I cleared logs (deleting the old one). On the other hand, in prod environment symfony generated a blank frontend_prod.log after performing clear logs command. I'm not sure what had caused this and if this have anything to do with logging not working in dev environment.

Here are the settings in my settings.yml and factories.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

Please let me know what I'm doing wrong. Thank you.

Update:

I had also tried calling the following in actions.class.php

$this->logMessage('ErrorMessageHere', 'err');

Same result, I got the Error Message in prod environment but not in dev environment.

I also tried to reset permission by calling

    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

no error appeared and it looks like log folder has the right permissions. Same thing happened, in dev environment symfony did not create the log file frontend_dev.log, but in prod mode after clearing logs, a blank frontend_prod.log was created.

This is my 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();

Update 2:

I just found something interesting with my logs in dev and prod environment.

In my symfony project there are many modules in apps, I had been testing message logging in 2 modules under both Actions and Templates. However, today I noticed an interesting event, when I tested in other modules, dev environment produced error message and prod didn't. And if I insert error logs into 4-5 modules, some of the logs will appear in frontend_dev.log and others will appear in frontend_prod.log . I tried clearing cache and clearing logs; still, the same modules would produce errors in frontend_dev.log and other modules would produce errors in frontend_prod.log

For example: I enabled prod environment in /web/index.php and inserted the following error log codes into 4 different actions.class.php in 4 different modules

$this->logMessage('errortest1', 'err');
$this->logMessage('errortest2', 'err');
$this->logMessage('errortest3', 'err');
$this->logMessage('errortest4', 'err');

If I enable both dev and prod error logging in prod environment. errortest1 and errortest2 will appear in frontend_dev.log and errortest3 and errortest4 will appear in frontend_prod.log If I only enable prod error logging in prod environment. frontend_dev.log will be empty and errortest3 and errortest4 will appear in frontend_prod.log If I only enable dev error logging in dev environment. errortest1 and errortest2 will appear in frontend_dev.log and frontend_prod.log will be empty

So I'm not sure what is going on, did my symfony project got corrupted?

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
TSCOconan
  • 85
  • 2
  • 9
  • I can't seem to fina any error there. Try to check you /log folder's permission – samura Nov 16 '11 at 23:57
  • On a side note, in your actions use this to log messages: $this->logMessage("Error!", "err"). Do not re-instantiate the sfContext singleton class in the action. – Flukey Nov 17 '11 at 12:15
  • Thanks guys for your help. I reset the project permissions by calling: "php symfony project:permission". I tried "$this->logMessage('ErrorMessage', 'err'); Same result, I was able to get the error message in prod environment but not in dev environment. I'll look into the dev_debug and prod_debug rules, maybe I'm missing something there. – TSCOconan Nov 17 '11 at 16:30
  • can you show us your frontend_dev.php file from the web directory ? – Manse Nov 17 '11 at 17:00
  • Added frontend_dev.php file. Thanks for look into the problem. – TSCOconan Nov 17 '11 at 17:35

1 Answers1

0

Might the "\n" at the end of the line be intefering with your code?

Try leaving a gap between the lines instead.

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

    logging_enabled:        true
    web_debug:              true
Jon Winstanley
  • 23,010
  • 22
  • 73
  • 116