Can I use the logging module in Revit Python Shell?

40 Views Asked by At

Is it possible to use Iron Python logging module in Revit Python Shell?

For example, this code works in RPS in sending logging messages to a file:

import logging
LOG_FILENAME = 'example.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)

logging.debug('This message should go to the log file')

But I want the message to show up on the RPS window the same way messages from the print statement does.

enter image description here

Is this possible? When I try to do so, no error occurs but no message appears either

Michelle

1

There are 1 best solutions below

0
Michelle On

I figured it out.

The logger module defaults to the IO Stream stderr. Stuff printed to stderr does not appear in the console window of Revit Python Shell. Redirecting logger to stdout gets the job done.

import logging
import sys

logging.basicConfig(stream=sys.stdout,level=logging.DEBUG)
logging.debug('This message should go to the RPS Console')

To figure it out, I had to dig thru RPS repository till I found python_27_lib.zip. After downloading that, I next had to find the logging directory and the file handlers.py. Reading thru that turned up the info about stderr. From there I just guessed that RPS might be redirecting stdout to its output window.

No info about any of this turned up on an internet search. For a Python newbie, this was quite a stretch.

I also learned that apparently RPS compiles the std Python library into a single DLL - RpsRuntime.dll

Michelle