如何debug,去哪找log

log和debug相关设置

  • show all errors by adding a few lines to your local testing site’s settings.php:

    1
    2
    3
    error_reporting(E_ALL);
    ini_set('display_errors', TRUE);
    ini_set('display_startup_errors', TRUE);
  • navigate to Configuration > DEVELOPMENT > Logging and errors (admin/config/development/logging) and select “All messages”.

  • 激活Debug mode
    激活后,drupal会禁用cache,js和css聚合,修改error_log为详细级别等

    1. 拷贝文件到sites/default/

      1
      cp sites/example.settings.local.php sites/default/settings.local.php
    2. 放开sites/default/settings.php中以下内容

      1
      2
      3
      if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
      include $app_root . '/' . $site_path . '/settings.local.php';
      }
  • 开启Twig templates debug
    sites/default/services.yml

    1
    2
    3
    twig.config:
    debug: true
    auto_reload: true
  • 开启Render API cache debug
    sites/default/settings.local.php

    1
    2
    3
    $settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';
    $settings['cache']['bins']['render'] = 'cache.backend.null';
    $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
  • Switch on strict PHP error reporting
    check through your php.ini file and set error reporting to E_ALL | E_STRICT.

log

  1. 网站不能访问

    1. 查看apache log

      1
      tail -f 'C:\Program Files (x86)\DevDesktop\apache\logs\error.log'
    2. drush watch dog

      1
      drush wd-show --tail
    3. 通过syslog module 查看log
      syslog需要关闭dblog,不适用于开发时使用

  2. 网站可以访问
    1. 通过dblog module查看系统事件log
      Your site captures system events in a log to be reviewed by an authorized individual at a later time. The log is a list of recorded events containing usage data, performance data, errors, warnings, and operational information. It is vital to check the log on a regular basis as it is often the only way to tell what is going on.
      You can find your site’s recent log messages in the Manage administrative menu by navigating to Reports > Recent log messages (admin/reports/dblog).

debug tools

  1. phpstorm + xdebug
  2. Twig_Xdebug module
  3. devel module

参考资源

Show all errors while developing
Database Logging module overview
Syslog module overview
Debugging Twig templates
drupal-8-debugging-techniques