Python Errors and Logging from Scripts

Posted on
Wed Oct 04, 2023 2:05 am
mkbean offline
Posts: 9
Joined: Jan 23, 2014

Python Errors and Logging from Scripts

Hey.

I'm finding Indigo's python scripting increasingly frustrating as i get more advanced. wondered if anyone had any ideas of experience.

1. Scripts seem to fail silently, particularly if they are run from a file and not "embedded python'", how can i catch these errors?

2. How can i log to the indigo log in .py scripts that are in the Python3-includes folder, i can "print" which appears in the interactive console but thats as far as i've managed to get.

Thanks,

Daniel.

Posted on
Wed Oct 04, 2023 4:37 am
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Python Errors and Logging from Scripts

mkbean wrote:
1. Scripts seem to fail silently, particularly if they are run from a file and not "embedded python'", how can i catch these errors?

There's a straightforward way to do this. The following script is run from a file in an Indigo action:

Code: Select all
"""
Example of how to access logger levels in linked and embedded scripts.
"""

indigo.server.log("debug", level=10)
indigo.server.log("info", level=20)
indigo.server.log("warning", level=30)
indigo.server.log("critical", level=40)
indigo.server.log("error", level=50)

mkbean wrote:
2. How can i log to the indigo log in .py scripts that are in the Python3-includes folder, i can "print" which appears in the interactive console but thats as far as i've managed to get.


This example is a little bit more complex just to show what's possible. I've saved this script to the Python3-includes folder:

Code: Select all
"""
Another example of how to access logger levels in linked and embedded scripts.
"""

import indigo  # required, or you'll get a syntax error
import logging

indigo.server.log("debug message", level=logging.DEBUG)
indigo.server.log("info message", level=logging.INFO)
indigo.server.log("warning message", level=logging.WARNING)
indigo.server.log("error message", level=logging.ERROR)
indigo.server.log("critical message", level=logging.CRITICAL)


EDIT: ( saved as "logging_test.py" in the includes folder, then you "import logging_test" someplace else.)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 15 guests