Skip to content

Commit

Permalink
Merge pull request #8564 from kenjis/docs-improve-debugging
Browse files Browse the repository at this point in the history
docs: improve debugging
  • Loading branch information
kenjis authored Feb 20, 2024
2 parents 0189cad + eb03676 commit f78b67a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.
15 changes: 10 additions & 5 deletions user_guide_src/source/database/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ uses this to collect the queries to display in the Toolbar.
The Events
**********

.. _database-events-dbquery:

DBQuery
=======

This event is triggered whenever a new query has been run, whether successful or not. The only parameter is
a :doc:`Query </database/queries>` instance of the current query. You could use this to display all queries
in STDOUT, or logging to a file, or even creating tools to do automatic query analysis to help you spot
potentially missing indexes, slow queries, etc.
This event is triggered whenever a new query has been run, whether successful or
not. The only parameter is a :doc:`Query </database/queries>` instance of the
current query.

You could use this to display all queries in STDOUT, or logging to a file, or
even creating tools to do automatic query analysis to help you spot potentially
missing indexes, slow queries, etc.

An example usage might be:
An example to log all queries:

.. literalinclude:: events/001.php
7 changes: 1 addition & 6 deletions user_guide_src/source/installation/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,4 @@ After that, reload the page. You will see the error and the back trace.
CodeIgniter Error Logs
----------------------

CodeIgniter logs error messages, according to the settings in **app/Config/Logger.php**.

You can adjust the error threshold to see more or fewer messages. See :ref:`Logging <logging-configuration>` for details.

The default configuration has daily log files stored in **writable/logs**.
It would be a good idea to check them if things aren't working the way you expect!
See :ref:`codeigniter-error-logs`.
52 changes: 40 additions & 12 deletions user_guide_src/source/testing/debugging.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
**************************
##########################
Debugging Your Application
**************************
##########################

.. contents::
:local:
:depth: 2

================
Replace var_dump
================
*************
Checking Logs
*************

While using XDebug and a good IDE can be indispensable to debug your application, sometimes a quick ``var_dump()`` is
all you need. CodeIgniter makes that even better by bundling in the excellent `Kint <https://kint-php.github.io/kint/>`_
debugging tool for PHP. This goes way beyond your usual tool, providing many alternate pieces of data, like formatting
timestamps into recognizable dates, showing you hexcodes as colors, display array data like a table for easy reading,
and much, much more.
.. _codeigniter-error-logs:

CodeIgniter Error Logs
======================

CodeIgniter logs error messages, according to the settings in **app/Config/Logger.php**.

The default configuration has daily log files stored in **writable/logs**.
It would be a good idea to check them if things aren't working the way you expect!

You can adjust the error threshold to see more or fewer messages. See
:ref:`Logging <logging-configuration>` for details.

Logging All SQL Queries
=======================

All SQL queries issued by CodeIgniter can be logged.
See :ref:`Database Events <database-events-dbquery>` for details.

********************
Replacing var_dump()
********************

While using Xdebug and a good IDE can be indispensable to debug your application,
sometimes a quick ``var_dump()`` is all you need. CodeIgniter makes that even
better by bundling in the excellent `Kint <https://kint-php.github.io/kint/>`_
debugging tool for PHP.

This goes way beyond your usual tool, providing many alternate pieces of data,
like formatting timestamps into recognizable dates, showing you hexcodes as colors,
display array data like a table for easy reading, and much, much more.

Enabling Kint
=============
Expand All @@ -33,6 +59,7 @@ The ``d()`` method dumps all of the data it knows about the contents passed as t
allows the script to continue executing:

.. literalinclude:: debugging/001.php
:lines: 2-

dd()
----
Expand All @@ -45,14 +72,15 @@ trace()
This provides a backtrace to the current execution point, with Kint's own unique spin:

.. literalinclude:: debugging/002.php
:lines: 2-

For more information, see `Kint's page <https://kint-php.github.io/kint//>`_.

.. _the-debug-toolbar:

=================
*****************
The Debug Toolbar
=================
*****************

The Debug Toolbar provides at-a-glance information about the current page request, including benchmark results,
queries you have run, request and response data, and more. This can all prove very useful during development
Expand Down

0 comments on commit f78b67a

Please sign in to comment.