How to use Python to write an error to the log

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
User avatar
bob
Posts: 500
Joined: Wed Jun 14, 2006 7:55 am

How to use Python to write an error to the log

Post by bob »

How do you use Python to write to the log in the same manner you would Applescript? Can you make it red?

Like so;

Code: Select all

Script Error                    embedded script: invalid syntax
thanks,

bob
bschollnick2
Posts: 1355
Joined: Sun Oct 17, 2004 8:21 am
Location: Rochester, Ny
Contact:

Re: How to use Python to write an error to the log

Post by bschollnick2 »

bob wrote:How do you use Python to write to the log in the same manner you would Applescript? Can you make it red?

Code: Select all

Script Error                    embedded script: invalid syntax
Bob, you didn't include your test script... So it's hard to see what is going wrong.... But....

indigo.server.log ("text to write to log", isError=True)

or

self.debugLog ("text to write to log", isError=True)

should work fine, depending on what your trying to do.

- Ben
------
My Plugins for Indigo (v4, v5, and v6) - http://bit.ly/U8XxPG

Security Script for v4 - http://bit.ly/QTgclf
for v5 - http://bit.ly/T6WBKu

Support Forum(s) - http://www.perceptiveautomation.com/userforum/viewforum.php?f=33
User avatar
bob
Posts: 500
Joined: Wed Jun 14, 2006 7:55 am

Re: How to use Python to write an error to the log

Post by bob »

Ben,

Thanks for your reply. I have Python script that parses an xml file on my network. Sometimes it doesn't make the connection and I get a URLError. The error is written to the log but does not have "Script Error" title in the log. I want the script to write the error to the log as a Script Error. See my script and the error here;

http://www.perceptiveautomation.com/use ... =18&t=8856

thanks for any help!

bob
bschollnick2
Posts: 1355
Joined: Sun Oct 17, 2004 8:21 am
Location: Rochester, Ny
Contact:

Re: How to use Python to write an error to the log

Post by bschollnick2 »

bob wrote:Ben,

Thanks for your reply. I have Python script that parses an xml file on my network. Sometimes it doesn't make the connection and I get a URLError. The error is written to the log but does not have "Script Error" title in the log. I want the script to write the error to the log as a Script Error. See my script and the error here;

http://www.perceptiveautomation.com/use ... =18&t=8856
See the follow up in the other thread....
------
My Plugins for Indigo (v4, v5, and v6) - http://bit.ly/U8XxPG

Security Script for v4 - http://bit.ly/QTgclf
for v5 - http://bit.ly/T6WBKu

Support Forum(s) - http://www.perceptiveautomation.com/userforum/viewforum.php?f=33
nsheldon
Posts: 2469
Joined: Mon Aug 09, 2010 2:12 pm
Location: CA
Contact:

Re: How to use Python to write an error to the log

Post by nsheldon »

bob wrote:... The error is written to the log but does not have "Script Error" title in the log. I want the script to write the error to the log as a Script Error.
Use

Code: Select all

indigo.server.log("Text in log file", "Script", isError=True)
This will cause the error log type to show up as "Script Error" in your Indigo log. I'd recommend, however, using something more specific to the script returning the error, such as "XML Reader Script Error" rather than a generic "Script Error", so that you can track which script it is returning the error.
Locked

Return to “Extending Indigo with Plugins and Python”