Comprehensive Guide to Debugging and Logging in Empress for Developers

Introduction

In this guide, we’ll be immersing ourselves in the technical depth of Empress, focusing on the Server and Client Debugging feature. The Empress debugging feature is crucial in the development process, helping developers identify and fix issues in the system.

Server

Debugging server-side code in Empress is as simple as running the bench start command. This command initiates all processes listed in the Procfile and logs their outputs in the terminal window. Here is an example:

▶ bench start

Print statements written in your Python code will appear either in the web: process log for request/response operations or in one of the worker_ processes for background jobs.

VSCode Debugging

For Visual Studio Code users, you can set breakpoints in your code and debug right in your editor.

Logging

In production, logs are crucial for keeping track of your Empress environment. By default, logs are stored under the ./logs folder in your bench. From Empress Version 13 onwards, logs are also available at the site level, under ./sites/{site}/logs.

Console

Empress provides an iPython shell to help you interact with the Python API. After running the following command, Empress will import frappe, initialize it, and connect to the database.

▶ bench --site [sitename] console

Client

Client-side debugging in Empress is as simple as adding a debugger statement in your JavaScript file. Open your DevTools in your browser to pause on the statement.

frappe.db.get_value('Task', 'TASK00004', 'status')
    .then(values => {
        debugger
        console.log(values);
    })

To interact with the Client API, open your browser’s console and use the globally available frappe object.

Debugging in VS Code / Debug Adapter Protocol

To debug Empress in Visual Studio Code, follow these steps:

  1. Update your Procfile.
  2. Install the Python Extension for VS Code.
  3. Update your launch.json.
  4. Start debugging.

Conclusion

The Empress Server and Client Debugging feature is a powerful tool for developers. It provides the ability to identify, track, and fix issues, enhancing the robustness and reliability of the software. By understanding and effectively utilizing this feature, developers can streamline their development process and build business solutions that meet their specific needs.