Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with Python built-in logging module

0 REPLIES 0
Reply
Message 1 of 1
j.han97
140 Views, 0 Replies

Problem with Python built-in logging module

Hi all,

 

The Application.log() has very limited functionality, therefore I would like to use the Python built-in logging module.

 

However, some unexpected problems are noticed:

 

1. The logging.basicConfig failed to set the format of the log messages. After I executed the code below, I checked the relevant variables in VSCode and it showed that the formatter is still the default format.

 

The code is as below:

import adsk.core, adsk.fusion, adsk.cam, traceback
import logging
 
logging.basicConfig(filename='<change to your own path>', 
                    filemode='w',
                    level=logging.DEBUG, 
                    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    )

_app = adsk.core.Application.get()
_ui = _app.userInterface

def run(context):
    try:            
        logging.debug('This is message 1')
        logging.warning('This is message 2')
        logging.error('This is message 3')
        logging.shutdown()
    except:
        if _ui:
            _ui.messageBox('Bye bye world')

 

Screenshot in debugging mode in VSCode. Note that the 'BASIC_FORMAT' is not changed.

jhan97_0-1641865910069.png

 

2. The second question is quite related to the first one: When I use logging module for different projects (for example, in Script 1 and AddIn 1 in Fusion 360 simultaneously, the filename arguments in logging.basicConfig does not change the log file location.

 

This results in log messages from different projects end up in the SAME file, despite the fact that I have set different log file locations for them.

 

This, again, is probably due to the logging.basicConfig not having effect as it supposed to.

 

The problem is, I have been using logging module in another project (outside Fusion 360) without issue. Hence, I am wondering if this has something to do with the embedded version of Python in Fusion 360 (Maybe something interferes the operation of logging module?).  

 

Thank you all for your time.

Labels (2)
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report