Debugging

01 error

YetiForce CRM is a very advanced system that has thousands of files and hundreds of dependencies and the numbers are growing each day. That's why to be able to analyse problems within the system, many logging mechanisms have been created and if there is a need they can be activated in a corresponding place. There are also other ways to approach and analyse errors, but they are not listed in this article because they may require an advanced level of programming or are specific for a particular environment and implemented functionalities. 

Introduction

Please note, that debugging does not only mean zeros and ones, it is a sort of state of mind :] It is necessary to understand a problem in such a way that helps to find its cause. Otherwise, you can waste a lot of time. Various technologies are debugged in different locations (e.g. HTML, CSS, JS, AJAX -it's best to debug them in the browser). Various tools should be used for debugging, such as XDebug, server logs, application logs. For the browsers, it is recommended to use Google Chrome. Sometimes it is necessary to add something unusual to the code so it will display an error in a corresponding place. A good idea might be to perform simple network tests to eliminate problems between the server and user's browser. 

PHP Logs

In order to verify problems or errors it is necessary to enable logs and the display of server messages. Otherwise, the server will not be able to inform about problems, e.g. about a short execution time for scripts. Change log-errors and display_errors to On in php.ini configuration. If the configuration allows to overwrite PHP parameters, change values in .htaccess file. Additional configuration using .htaccess. Before debugging, do not forget to check the parameters in the panel in the Server configuration section.
 
  1. cache/logs/phpError.log -there is a pre-defined file that saves PHP logs. Log appearance is determined by a few indirect factors, e.g. web server configuration.
  2. cache/logs/errors.log - logs controlled by the CRM system 
  3. cache/logs/system.log - primary logs for debigging the CRM system, recorded information dapends on the selected level of recording
  4. cache/logs/davException.log - error logs for DAV integration 
  5. cache/logs/davDebug.log - debugging logs for DAV integration 
  6. cache/logs/webserviceDebug.log -debugging logs for webservises
  7. cache/logs/webserviceErrors.log -  error logs for webservices 
  8. cache/logs/viewer-debug.log - debugging logs for data displaying layer - Smarts
  9. cache/logs/smtp - mail logs for smtp
  10. cache/logs/ldap -mail logs for ldap
  11. cache/logs/imap- mail logs for imap
  12. cache/logs/sql- mail logs for sql
  13. cache/logs/session- mail logs for session
  14. cache/logs/sql- mail logs for sql
  15. cache/logs/update.log- error logs for the mechanism used to update the system 

When files described above do not exist, then after enabling logs they will be created (as long as the application has adequate permissions in the file system). 

System Logs

To enable recording of logs to files set true for 'LOG_TO_FILE' [9 line] parameter in the config/debug.php file and then set a level of recording changes LOG_LEVELS. Below are the levels of log4php debugging (from the one that shows the least to the one showing the most):
  • profile
  • trace
  • info
  • warning
  • error
Example:
  • ['error']
  • ['error', 'warning', 'info', 'trace', 'profile']
  • 'All'
  • 3
Logs will be registered in the following file: cache/logs/system.log. The "cache/logs/" directory needs to have write permissions. 

MySQL Logs

You can stop the system each time a database error appears. In order to do it go to the config/debug.php file, and change the value of the SQL_DIE_ON_ERROR variable to true. If you enable the DISPLAY_DEBUG_BACKTRACE variable, the system will display a list of files (together with the row numbers) that were executed since the script started until the error occurred. This variable works only when SQL_DIE_ON_ERROR is also enabled, otherwise the system will only display an error message. 

Smarty Logs

There is also a possibility to debug smarty in the system; it is necessary to enable the DEBUG_VIEWER variable in config\debug.php file. It is also possible to put the same logs in a popup widow by using DISPLAY_DEBUG_VIEWER variable and setting its value to true.

Mailbox debugging [Roundcube]

Enable debugging in config/debug.php configuration file:
$config['debug_level'] = 1;
In Roundcube various elements can be debugged:
// System error reporting, sum of: 1 = log; 4 = show, 8 = trace
'ROUNDCUBE_DEBUG_LEVEL' => 1,
// Devel_mode this will print real PHP memory usage into logs/console and do not compress JS libraries
'ROUNDCUBE_DEVEL_MODE' => false,
// Activate this option if logs should be written to per-user directories.
 
// Data will only be logged if a directry cache/logs// exists and is writable.
'ROUNDCUBE_PER_USER_LOGGING' => false,
 
// Log sent messages to cache/logs/sendmail or to syslog
'ROUNDCUBE_SMTP_LOG' => false,
 
// Log successful/failed logins to cache/logs/userlogins or to syslog
'ROUNDCUBE_LOG_LOGINS' => false,
 
// Log session authentication errors to cache/logs/session or to syslog
'ROUNDCUBE_LOG_SESSION' => false,
 
// Log SQL queries to cache/logs/sql or to syslog
'ROUNDCUBE_SQL_DEBUG' => false,
 
// Log IMAP conversation to cache/logs/imap or to syslog
'ROUNDCUBE_IMAP_DEBUG' => false,
 
// Log LDAP conversation to cache/logs/ldap or to syslog
'ROUNDCUBE_LDAP_DEBUG' => false,
 
// Log SMTP conversation to cache/logs/smtp or to syslog
'ROUNDCUBE_SMTP_DEBUG' => false,
 
in config/debug.php file you will find more variables that allow to debug more complex communication elements between the mail server and Roundcube. 

DAV debugging

In the config/debug.php configuration file you can also enable debugging of DAV library.

'DAV_DEBUG_EXCEPTIONS' => true, 'DAV_DEBUG_PLUGIN' => false, - this parameter enables an additional plugin that is used for loging/saving all data that is received and sent by the server to cache/logs/davDebug.log file.

Examples

Examples showing to developers how to display errors and debug the code:

  • trigger_error('TempDebug: $someVariable="'.print_r($someVariable, TRUE) .'"');
  • trigger_error('TempDebug: $smallArray=<PRE>"'.print_r($smallArray, TRUE) .'"</PRE>');
  • trigger_error('TempDebug: $largeArray:...'); print_r("<PRE>"); print_r($largeArray); print_r("</PRE>");

Summary

All parameters that allow for analysis and debugging the system will be located in config/debug.php file.

  • piątek, 11 sierpień 2017