Skip to content

Commit d9bde12

Browse files
jasonhildebrandCito
authored andcommitted
Debugging doc updates (#3)
Added documentation on debugging using pdb
1 parent 75f3e70 commit d9bde12

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

docs/appdev.rst

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,16 @@ When creating the Application instance, it takes a ``development`` flag as argum
310310
print
311311
~~~~~
312312

313-
The most common technique is the infamous ``print`` statement which has been replaced with a ``print()`` function in Python 3. The results of ``print()`` calls go to the console where the WSGI server was started (not to the HTML page as would happen with CGI). In production mode, you can specify an ``AppLogFilename`` in ``Application.config``, which will cause the standard output and error to be redirected to this file.
313+
The most common technique is the infamous ``print`` statement which has been replaced with a ``print()`` function in Python 3. The results of ``print()`` calls go to the console where the WSGI server was started (not to the HTML page as would happen with CGI). If you specify ``AppLogFilename`` in ``Application.config``, this will cause the standard output and error to be redirected to this file.
314+
315+
For convenient debugging, we recommend you use a clause like this in your ``Application.config`` file::
316+
317+
if Development:
318+
AppLogFilename = None
319+
else:
320+
AppLogFilename = 'Logs/Application.log'
321+
322+
This will prevent standard output and error from being redirected to the log file in development mode, which makes it easier to find debugging output, and also makes it possible to use ```pdb``` (see below).
314323

315324
Prefixing the debugging output with a special tag (such as ``>>``) is useful because it stands out on the console and you can search for the tag in source code to remove the print statements after they are no longer useful. For example::
316325

@@ -331,7 +340,7 @@ While this is totally useful during development, giving away too much internal i
331340
Reloading the Development Server
332341
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
333342

334-
When a servlet's source code changes, it is reloaded. However, ancestor classes of servlets, library modules and configuration files are not. You may wish to enable the auto-reloading feature when running the development server, by adding the ``-r`` or ``--reload`` option to the ``webware seve command`` in order to mitigate this problem.
343+
When a servlet's source code changes, it is reloaded. However, ancestor classes of servlets, library modules and configuration files are not. You may wish to enable the auto-reloading feature when running the development server, by adding the ``-r`` or ``--reload`` option to the ``webware serve command`` in order to mitigate this problem.
335344

336345
In any case, when having problems, consider restarting the development server (or the WSGI server you are running in production).
337346

@@ -345,6 +354,19 @@ Assertions are used to ensure that the internal conditions of the application ar
345354
assert shoppingCart.total() >= 0, \
346355
f'shopping cart total is {shoppingCart.total()}'
347356

357+
Debugging using PDB
358+
~~~~~~~~~~~~~~~~~~~
359+
To use python's built-in debugger ```pdb```, see the tip above about setting ```AppLogFilename``` for convenient debugging.
360+
361+
To have Webware automatically put you into pdb when an exception occurs, set this in your ``Application.config`` file::
362+
363+
EnterDebuggerOnException = Development
364+
365+
A quick and easy way to debug a particular section of code is to add these lines at that point in the code::
366+
367+
import pdb
368+
pdb.set_trace()
369+
348370
Debugging in an IDE
349371
~~~~~~~~~~~~~~~~~~~
350372

0 commit comments

Comments
 (0)