Skip to content

docs: improve debugging #8564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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