Often, during the development of an application, it is necessary to look at the execution of processes step by step to catch an error or understand how to improve the application.
Let’s look at debugging and logging methods in AppMaster.
Frontend Debugging
To debug the frontend, use the Toast and Notification blocks. These blocks show notifications in the frontend. If you don’t know how a block worked, you can pass the values of this block to Notification and see in the frontend what values the completed block gives.
Toast and Notification blocks can be used in long business processes to determine where something is going wrong. The Toast and Notification blocks accept data in String format. If you need to display data stored in other formats, use toString or toJSON blocks (if you need to display an object or an array of objects from the database).
Standard logging
Every AppMaster project has standard logging. It is located on the Project / Deploy Stats tab.
If there is a need to write something additional, there is a particular Write to log block in the backend business process.
This block has two input fields:
Label – the title that will be written to the log in string format; Input – any value to be stored in the log.
Create custom logger
When many requests are constantly made to the application, it becomes inconvenient to write everything to a common log. It is better to make your own logger, following the instructions:
Create a data model – Log. Add fields to it:
- Label – for the title of the entry;
- Text – for the post body.
Now create a BP on the backend, which will save the necessary values to the log. Set the fields for the Start block:
- Label – in string format;
- Text – in string format.
Now, let's use the Make block and create a record by passing the fields from the Start block to it.
Save the record to the database using the Create block.
Now create an endpoint for the new business process to access it from the frontend. Go to the Endpoints tab and create a new one.
- Select the POST method.
- Set the URL.
- Select a group.
- Install the created business process:
Now, we can use the created business process in those places where we want to write logs.
Let's take the Task page as an example. It contains a table with entries about user tasks. And also, on this page, there is a form for adding entries. We made such a page here and here.
Let's log the process of adding records. Open the Workflow button that adds records.
Add the business process after the Server Request POST /task block. Connect fields _error and text. The label field will be set by default.
Now, when a new record is created, this event is logged.