patricksurry / pysimconnect

Simple, efficient wrapper for FlightSimulator 2020's SimConnect SDK
MIT License
25 stars 9 forks source link

SimConnect class produces unwanted verbose output #10

Open lucasangarola opened 1 year ago

lucasangarola commented 1 year ago

During the process of integrating this great implementation on my simulation software I realized that the SC class will log directly to logging. For those that would like to import the module and use it as-is (my case), it would be great that the exceptions are propagated without logging involved. In this way I would be able to handle and print what is necessary on my software. At the moment, when the Sim is not running, the class will spam my software logging console with unwanted messages.

Suggestion: I would suggest to add a verbose flag as part of the class init, which will enable any logging information. You can make it True by default, but at least I get some control :)

class SimConnect:
    def __init__(
            self,
            name='pySimConnect',
            dll_path=_dll_path,
            default_receivers=_default_receivers,
            poll_interval_seconds=0.05,
            verbose: bool = True):

Thank you very much in advance!

patricksurry commented 1 year ago

Thanks for the feedback.

You're right it'd be better if it configured a named logger (see https://stackoverflow.com/questions/35325042/python-logging-disable-logging-from-imported-modules) and used a less verbose default. I'll take a look at that.

In the short term, you should be able to change the default log level by setting an environment variable (see https://github.com/patricksurry/pysimconnect/blob/master/simconnect/sc.py#L21).

e.g. on *nix platforms try export LOGLEVEL=WARNING and you should get less noise.

lucasangarola commented 1 year ago

Thank you for your answer! I would rather wait for the proper fix. I use logger across my application, hence I don't want to modify the logging level. Looking forward to your fix!