Web-Based console for Raspberry Pi: debug methods

Posted by:

|

On:

|

To effectively fix problems with webpages, both front-end and back-end development require different tools.

The Chrome Developer Tools is a powerful toolkit specifically designed for front-end developers. It offers an extensive set of features and utilities to help debug issues, optimize performance, and improve the user experience of websites and web applications. To access it, simply press F12 or right-click on a web page and choose “Inspect” from the context menu. The Developer Tools panel will then open, typically positioned on the right side of the browser window. The Chrome Developer Tools offer a wide range of features that are so extensive that it takes time to become proficient in using them. Once I have gained more knowledge, I plan to write a blog post exploring these features in detail.

For backend development, I utilize Python’s logging library to facilitate debugging. I have developed a short Python script that can establish a logging system for the backend application. The Python script can be downloaded from GitHub using the following link

https://github.com/FelixT123/CS-Student/blob/main/web-based%20console/logger.py

The code offers a convenient solution for configuring a logger within the python application. To make use of the getLogger function, first import the logger python , then create a logger object with a specific name in the python files, usually the name of the Python file where the messages are logged.

        import logger        
        log = logger.getLogger('server.py')

You can capture important information, display it on the console, and save it to log files simultaneously by utilizing commands such as

        log.debug('Program started')
        log.info(f"name={name}")

The log messages follow a specific format, which includes a timestamp, logger name, log level, and the actual log message. For example:

[2024-02-23 00:03:48,475][server.py ][DEBUG ] Program started
[2024-02-23 00:03:48,477][server.py ][INFO ] name=MyApp2
[2024-02-23 00:03:48,477][server.py ][INFO ] LED_pin_arr=[{'name': 'RED', 'pin': 13}, {'name': 'GREEN', 'pin': 14}]
[2024-02-23 00:03:48,477][server.py ][INFO ] configuration loaded
[2024-02-23 00:03:48,490][server.py ][INFO ] listening....

You can conveniently trace the Python files that the application runs and the real-time content of the variables by including relevant information in the log messages. This can greatly assist in troubleshooting and debugging your code.

The log file is rotated on a daily basis, ensuring efficient management of log files. This rotation process helps maintain log files in an organized manner.

Posted by

in