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: 

Questions regarding Application.log()

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
j.han97
363 Views, 4 Replies

Questions regarding Application.log()

Hi all,

 

I am trying to using Application.log to log my addin. I have learnt that I can log to file using Application.log(message, log_level, 0) which 0 indicates logging to file.

 

My questions are:

1. Where is the log file located? Can I set the path of the log file? 

2. Can I log in Console & File at the same time? Or do I need to call Application.log twice, with each of it logging to console & file respectively?

 

Thank you!

Labels (2)
4 REPLIES 4
Message 2 of 5
j.han97
in reply to: j.han97

In fact, I have been trying to use Python native logging module for logging, but it does not output any file. 

import adsk.core, adsk.fusion, traceback
import logging

_app = adsk.core.Application.get()
_ui = _app.userInterface
_path = __file__[:__file__.rfind('/')]


def run(context):
    try:    
        log_path = _path+'/logging.log'
        _ui.messageBox(f'Log path is {log_path}')
        logging.basicConfig(filename=log_path, level=logging.DEBUG)     
        logging.debug('Hi ya')
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

When I ran this code, there was no error, but no log file was produced as well. 

 

Does anyone has experience in using logging module in Fusion 360? Any help is appreciated!

Message 3 of 5
kandennti
in reply to: j.han97

Hi @j.han97 .

 

I tried to see where the file was written to, and it was written to the log file in the following folder.(Win)
C:\Users\<User_Name>\AppData\Local\Autodesk\Autodesk Fusion 360\<User_ID>\logs

There are multiple files, but if you check the timestamp, you should be able to find the latest log file.

 

If you want to check the file more quickly, you can use the following TextCommand to open the log file.
Application.Log

 

I made this script and ran it.
# Fusion360API Python script

import traceback
import adsk.core

def run(context):
    ui: adsk.core.UserInterface = None
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface

        FILE_LOG_TYPE = adsk.core.LogTypes.FileLogType
        app.log('hoge', adsk.core.LogLevels.ErrorLogLevel, FILE_LOG_TYPE)
        app.log('huga', adsk.core.LogLevels.WarningLogLevel, FILE_LOG_TYPE)
        app.log('piyo', adsk.core.LogLevels.InfoLogLevel, FILE_LOG_TYPE)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

1.png

 

In my opinion, this is not for use during development, but is useful when you release an add-in and receive reports of problems from add-in users, and ask them to send you their logs so that you can investigate the problems.
 
This log file was also included in the zip file that was created by using this command.
2.png

 

 

 

 

Message 4 of 5
BrianEkins
in reply to: kandennti

kandennti posted some useful information.  I would have expected much of that to be in the documentation but the documentation doesn't explain anything useful for the log method.  I suspect there's a mistake and it didn't get updated, but the post from kandennti should give you everything you need.

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 5
j.han97
in reply to: j.han97

Thank you both for your answers! These are some very useful information for me.

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