Announcement

Collapse
No announcement yet.

Debugging PHP Code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Debugging PHP Code

    For those that may not be aware, the following is really useful when debugging PHP code:

    Code:
    $GLOBALS['log']->debug('Here is my variable:', [$variable]);
    You just need to ensure that in your `data\config.php`, the relevant logging `level` is enabled for your output:

    Code:
    'logger' => [
            'path' => 'data/logs/espo.log',
            'level' => 'DEBUG',
            'rotation' => true,
            'maxFileNumber' => 30
        ],
    Then you just need to check your log file (in the above path) for the messages. This has helped us massively!

    Available options are:

    Code:
    DEBUG
    INFO
    NOTICE
    WARNING
    ERROR
    CRITICAL

  • #2
    Thanks blueprint I am currently struggling with a PHP stupid bug. Sorry if this is quite obvious but in which script do I write
    Code:
     
     $GLOBALS['log']->debug('Here is my variable:', [$variable]);
    ?

    Comment


    • #3
      Originally posted by telecastg View Post
      Thanks blueprint I am currently struggling with a PHP stupid bug. Sorry if this is quite obvious but in which script do I write
      Code:
      $GLOBALS['log']->debug('Here is my variable:', [$variable]);
      ?
      That all depends which script is causing you the issue.

      For example, I've recently been debugging some hooks so I've added the above code a number of times in the `beforeSave` function.

      I've also previously littered the majority of the ORM php files with debug statements just so I could figure out the program flow.

      Comment


      • telecastg
        telecastg commented
        Editing a comment
        Thanks so much, it's like using "console.log" to debug javascript, excellent !
        Last edited by telecastg; 01-22-2020, 03:58 PM.

    • #4
      Thanks blueprint, great tip!

      I add a note: I found the default logger[] array setting in config-internal.php. This is important, because this will override the logger[] settings defined in config.php.

      Just had to edit the default WARNING level to DEBUG in config-internal.php, and logging works well.

      Comment

      Working...
      X