Drupal показывать ошибки

Set Drupal to show all errors when developing your module.

Some errors are only reported when all PHP error reporting is switched on. Without the error reporting on, you get the dreaded White Screen of Death.

Check for errors behind the scenes

As an alternative between showing no errors and showing all errors, you may wish to monitor the errors being generated by your site by running

tail -f /var/log/apache2/error.log

on your server.

Change settings in your dev site

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

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

In addition, navigate to Administration→ Configuration→ Development → logging and errors and select «All messages». (This sets $conf['error_level'] = 2;.)

Switch on strict PHP error reporting

Or you can go through your development site’s php.ini file, in the php folder, and switch all error reporting on. To do this, check through your php.ini file and set error_reporting to E_ALL. The documentation there is very thorough, and you may find a different setting that’s better suited to your needs. Warning: as the PHP documentation states, this setting is only for development sites, not for production sites.

  1. Главная
  2. Форумы
  3. Техподдержка Drupal
  4. Установка и настройка

Как настроить выдачу ошибок сайтом? Например показывать ошибки ролям. Или не показывать название домена в ошибке.

Главные вкладки

  • Просмотр(активная вкладка)
  • Реакции

Аватар пользователя VasyOK
VasyOK


15 июля 2013 в 18:27


На всех сайтах рано или поздно возникают противные красные надписи.
Как настроить выдачу ошибок?
Например показывать ошибки только определенным ролям.
Или не показывать название домена в ошибке.

  • Drupal7
  • Установка и настройка
  • Блог
  • Войдите или зарегистрируйтесь, чтобы отправлять комментарии

Комментарии

Аватар пользователя Faceless
Faceless


15 июля 2013 в 21:29




Аватар пользователя VasyOK
VasyOK


15 июля 2013 в 23:57




Вообще никогда — это немножко не то что мне надо. Т.к. для никогда есть display:none Smile
За ссылку спасибо.
https://drupal.org/project/disable_messages — там и такое обсуждают тоже попробую.

Остается решить, как не показывать название домена.

Аватар пользователя drupby
drupby


16 июля 2013 в 0:29




«VasyOK» wrote:

Остается решить, как не показывать название домена.

пропускай в шаблоне или препроцессе_page массив $messages через функцию preg_replace или str_replace

Drupal надстраивает собственные разрешения на вывод ошибок, потому если вам необходим вывод ошибок на этапе разработки, то важно знать как разрешить их показ/протоколирование.

Чтобы не разбираться в конфигурации конкретно вашего веб-сервера, воспользуемся командами ini_set и error_reporting для настройки вывода PHP ошибок уже во время исполнения скрипта.

Инструкции нужно добавить в файл конфигурации вашего Drupal сайта (по умолчанию это — /sites/default/settings.php).

error_reporting(E_ALL);

ini_set(‘display_errors’, TRUE);

ini_set(‘display_startup_errors’, TRUE);

Это не гарантирует вывод ошибок, т.к. Drupal может иметь собственные настройки. Их можно изменить в админ панели — вот тут /admin/config/development/logging или жестко зафиксировав в конфигурации:

$conf[‘error_level’] = 2;

Это будет соответствовать выбору ‘All messages’ в админке.

Drupal 7

Написать комментарий


Данная запись опубликована в 24.01.2020 13:45 и размещена в drupal.
Вы можете перейти в конец страницы и оставить ваш комментарий.

Мало букафф? Читайте есчо !

Have you seen an error message in a Drupal site like this?

When you are building or modifying a Drupal site, the error above can sometimes appear and catch us in unexpected situations, but there is nothing much you can do. “Try again later” is not going to help. What will you do?

There is not much you can do about it, because there is not enough information to go further. By default, Drupal is configured not to display error messages. To find out what caused the errors, the error message display options require to be turned on first.

In this tutorial, you’ll learn how to turn on error display to help you debug.

WARNING: It’s important not to display error messages on a production site. The error messages could display sensitive information such as paths or server level user accounts.

To turn on the “Error Messages to Display”, go to the Administration menu, then go into Configuration > Development > Logging and errors (/admin/config/development/logging).

You will find the following configuration. There are 4 options available, and the default setting is “None”.

The 4 options are:

None

None is the default. Drupal will not display error messages. That’s why there is only very limited error information displayed.

Errors and warnings

Display both errors and warnings

All messages

Display all messages

All messages, with backtrace information

Display all messages, including a backtrace of all the functions that the system has gone through before the error

Turning on the other options, Drupal will display more error messages. The following is another example of error messages after turning on “All messages, with backtrace information”:

When more information is provided, it’s easier to isolate, test and identify what really caused the errors. Compared with the first error screen above, this one makes much more sense to start with. We are not going into the individual errors here. This is probably the first step to handle unknown error messages. Even though sometimes we need help from other people, this more detailed information is still necessary for them to follow up.

Recent Log Messages

In addition to the error screen, there is an area “Recent Log Messages” we can look into if the site is still working.

To go into this area, go to Administration Menu, go to Reports > Recent log messages (../admin/reports/dblog),

A list of recent log messages can be found here. Following is an example:

By clicking on the individual log, more details of that error message will be displayed. Below is an example.

Summary

Next time when we come across a run-time error, we can analyze what changes have been made, see if the errors are repeating, and see if things can be reversed.

In addition, turning on these error message displays to provide us more information, particularly a backtrace of the functions Drupal was executing, and collecting other log messages are additional steps we can take.

Even though we might need assistance from other people, this information is still important to them.

We hope these simple steps will be helpful in problem-solving, which sometimes can be very time-consuming.

If you got a generic error in Drupal and are not sure why then it’s time to enable Drupal Debug Mode options and error reporting.

This is not helpful :(

The website encountered an unexpected error. Please try again later.

This is really important for the backend as well as the frontend developers to see the full error on your screen while you are working because you might not know what is the exact issue with your Drupal site with just a generic error statement.

Drupal Backend Debug Options

Let’s go through some Drupal Debug options for the backend.

1. Enable backtrace errors

In Drupal, there is a way to backtrace the error and display it in the message area. You can put the following code in your settings.local.php or settings.php whichever you are using.

$config['system.logging']['error_level'] = 'verbose';

This makes the development easier on local as it will show the backtrace of the error which you can debug now.

2. Enable Error message to display

For local Drupal development, you should always enable «Error message to display» options in the «/admin/config/development/logging» configuration. This will give you more information about the errors.

Twig Debug Options for Frontend

Now let’s see how we can make frontend developer life easy by enabling Drupal Twig debugging options.

1. Enable Twig Debug Config

If you are a front-end developer and work around twig files to beautify the Drupal site then enabling the twig to debug configuration is a must.

You can enable this by copying the «sites/default/services.yml» file and renaming the new file to development.services.yml. Once you have the development.services.yml file you can just add a new twig debug parameter to it to enable the twig debugging and see the error information.

parameters:
    twig.config:
        debug: true

By enabling the twig config you will be able to find from which TWIG template file the HTML markup is coming.

Now you will also be able to see what the other twig template suggestions which will override the current template.

It will also let you know the theme in which the twig template file is located so that you don’t start editing the wrong twig file.

2. Debug variables in Twig

Once you have enabled twig.config debug option now you can a variable in a structured format in the frontend by using a simple line of code in the Twig file.

{{ dump(my_variable) }}

3. Disable Twig cache

Once the Twig debug option is enabled then you can also enable auto_reload and disable twig cache.

You can read more about Twig debugging here.

parameters:
    twig.config:
        debug: true
        auto_reload: true
        cache: false

More configs you should change…

1. Disable CSS and JS aggregation on the local environment in Drupal 8 by uncommenting the below lines to settings.local.php.

$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;

2. Disable Drupal 8 render cache and dynamic page caching by uncommenting the below lines to settings.local.php.

$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

3. If you are using the Drupal version greater than 8.4 then do add the following line in the settings.local.php file.s

$settings['cache']['bins']['page'] = 'cache.backend.null';

4. In the settings.local.php file uncomment the following line to enable the null cache service in Drupal 8.

$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';

Enable Drupal debugging with Drupal Console

If everything mentioned earlier is too much for you and you got access to Drupal Console then a single one-liner command can do the trick for you.

drupal site:mode dev

This Drupal console command will make changes in Drupal 8 configurations such as system.performance, views.settings, and system.logging to enable debugging. Command also makes changes to sites/default/services.yml file related to twig.config for frontend debugging.

And once you are done debugging the Drupal site you can revert all configurations back by running another command.

drupal site:mode prod

And the good part is this also rebuilds the cache at the end.

Conclusion

Debugging a Drupal site is not easy but with the right tools and tricks, you can make Drupal give you more information about the errors. And this information can help to debug the error better and faster.

NOTE: Make sure to clear the cache on your Drupal site after all the changes you have done for the local environment development.

WARNING: Make sure to not enable all these settings on the production site, unless you need to ;)

Понравилась статья? Поделить с друзьями:
  • Drupal ошибка php extensions
  • Drupal ошибка file
  • Drupal включить отображение ошибок
  • Drupal 7 ошибка 200
  • Drupal 7 вывод ошибки