199 lines
3.3 KiB
Markdown
199 lines
3.3 KiB
Markdown
## Tools for debug
|
|
|
|
<br>
|
|
|
|
### **INFO_DEBUG**
|
|
|
|
Show debugging information in a message box.
|
|
|
|
If you have any problems in your code during the development of your macros, you can [open a ticket][1] support in the system ticket of this project. Always copy the debugging information shown in your issue.
|
|
|
|
```py
|
|
import easymacro as app
|
|
|
|
def info():
|
|
app.msgbox(app.INFO_DEBUG)
|
|
return
|
|
```
|
|
|
|
![Info debug](img/install_01.png)
|
|
|
|
|
|
### **debug**
|
|
|
|
Show information at the terminal.
|
|
```py
|
|
import easymacro as app
|
|
|
|
def test_debug():
|
|
msg = 'Verify this information...'
|
|
app.debug(msg)
|
|
return
|
|
```
|
|
|
|
To view this message, you need to start LibreOffice from the command line:
|
|
```
|
|
soffice --calc
|
|
```
|
|
|
|
After executing the previous macro, you should see:
|
|
```
|
|
21/04/2023 17:04:49 - DEBUG - Verify this information...
|
|
```
|
|
|
|
<br>
|
|
|
|
### **info**
|
|
|
|
Show information messages at the terminal.
|
|
```py
|
|
import easymacro as app
|
|
|
|
def test_info():
|
|
msg = 'Starting process...'
|
|
app.info(msg)
|
|
return
|
|
```
|
|
|
|
```
|
|
11/08/2022 18:23:53 - INFO - Starting process...
|
|
```
|
|
|
|
<br>
|
|
|
|
### **error**
|
|
|
|
Show error messages at the terminal.
|
|
```py
|
|
import easymacro as app
|
|
|
|
def test_error():
|
|
msg = 'Error 505'
|
|
app.error(msg)
|
|
return
|
|
```
|
|
|
|
```
|
|
11/08/2022 18:27:34 - ERROR - Error 505
|
|
```
|
|
|
|
<br>
|
|
|
|
### **save_log**
|
|
|
|
Save log in file, automatically add date and time.
|
|
```py
|
|
import easymacro as app
|
|
|
|
def test_save_log():
|
|
|
|
app.save_log('/home/mau/log.txt', 'PyUNO')
|
|
app.save_log('/home/mau/log.txt', 'World Damn')
|
|
|
|
return
|
|
```
|
|
|
|
```
|
|
cat ~/log.txt
|
|
2022-08-11 18:30:11 - 'PyUNO'
|
|
2022-08-11 18:30:11 - 'World Damn'
|
|
```
|
|
|
|
<br>
|
|
|
|
### **msgbox**
|
|
|
|
Show any information in a message box.
|
|
```python
|
|
import easymacro as app
|
|
|
|
def message():
|
|
|
|
msg = 'Please, consume less.'
|
|
app.msgbox(msg)
|
|
|
|
msg = ('one', 2, 'three')
|
|
app.msgbox(msg)
|
|
|
|
msg = {'name': 'Teresa'}
|
|
app.msgbox(msg)
|
|
|
|
app.msgbox(app)
|
|
|
|
return
|
|
```
|
|
|
|
<br>
|
|
|
|
### **catch_exception**
|
|
|
|
Capture any error that occurs when running a macro.
|
|
|
|
!!! warning inline end "Caution"
|
|
|
|
Use this method only in development time. **Do not use it in production**.
|
|
|
|
```py
|
|
import easymacro as app
|
|
|
|
@app.catch_exception
|
|
def test_capture_error():
|
|
r = 1 / 0
|
|
return
|
|
```
|
|
|
|
```
|
|
11/08/2022 18:44:36 - ERROR - test_capture_error
|
|
Traceback (most recent call last):
|
|
File "/home/mau/.config/libreoffice/4/user/Scripts/python/pythonpath/easymacro/easytools.py", line 115, in func
|
|
return f(*args, **kwargs)
|
|
File "/home/mau/.config/libreoffice/4/user/Scripts/python/test.py", line 18, in test_capturar_error
|
|
r = 1 / 0
|
|
ZeroDivisionError: division by zero
|
|
```
|
|
|
|
<br>
|
|
|
|
### **mri**
|
|
|
|
[MRI][2] is the best extension to inspect any UNO LibreOffice object. You need to install it first so you can use it.
|
|
|
|
```py
|
|
import easymacro as app
|
|
|
|
def inspect_object():
|
|
obj = app.active
|
|
app.mri(obj)
|
|
return
|
|
```
|
|
|
|
<br>
|
|
|
|
### **inspect**
|
|
|
|
Inspect an object.
|
|
```py
|
|
import easymacro as app
|
|
|
|
def inspect_object():
|
|
doc = app.active
|
|
data = app.inspect(doc)
|
|
for p in data.properties:
|
|
app.debug(p)
|
|
for m in data.methods:
|
|
app.debug(m)
|
|
return
|
|
```
|
|
|
|
Send information of the object to worksheet.
|
|
```python
|
|
def inspect_object():
|
|
doc = app.active
|
|
app.inspect(doc, True)
|
|
return
|
|
```
|
|
|
|
|
|
[1]: https://git.cuates.net/elmau/easymacro/issues
|
|
[2]: https://github.com/hanya/MRI
|