Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def verbose_setter(value):
"""Use this to toggle the verbosity of all loggers at once"""
module_logger.setLevel(logging.DEBUG if value else logging.INFO)
qml_logger.setLevel(logging.DEBUG if value else logging.INFO)
projects_logger.setLevel(logging.DEBUG if value else logging.INFO)
formatter.verbosity = stm32pio.util.Verbosity.VERBOSE if value else stm32pio.util.Verbosity.NORMAL
Returns:
logging.Logger instance
"""
if dummy:
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
else:
logger = logging.getLogger('stm32pio')
logger.setLevel(logging.DEBUG if args_verbose_counter else logging.INFO)
handler = logging.StreamHandler()
formatter = stm32pio.util.DispatchingFormatter(
verbosity=stm32pio.util.Verbosity.VERBOSE if args_verbose_counter else stm32pio.util.Verbosity.NORMAL,
general={
stm32pio.util.Verbosity.NORMAL: logging.Formatter("%(levelname)-8s %(message)s"),
stm32pio.util.Verbosity.VERBOSE: logging.Formatter(
f"%(levelname)-8s %(funcName)-{stm32pio.settings.log_fieldwidth_function}s %(message)s")
})
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.debug("debug logging enabled")
return logger
"""Use this to toggle the verbosity of all loggers at once"""
module_logger.setLevel(logging.DEBUG if value else logging.INFO)
qml_logger.setLevel(logging.DEBUG if value else logging.INFO)
projects_logger.setLevel(logging.DEBUG if value else logging.INFO)
formatter.verbosity = stm32pio.util.Verbosity.VERBOSE if value else stm32pio.util.Verbosity.NORMAL
settings = Settings(prefix='app/settings/', qs_kwargs={ 'parent': app },
external_triggers={ 'verbose': verbose_setter })
# Use "singleton" real logger for all projects just wrapping it into the LoggingAdapter for every project
projects_logger = logging.getLogger('stm32pio_gui.projects')
projects_logger.setLevel(logging.DEBUG if settings.get('verbose') else logging.INFO)
formatter = stm32pio.util.DispatchingFormatter(
general={
stm32pio.util.Verbosity.NORMAL: logging.Formatter("%(levelname)-8s %(message)s"),
stm32pio.util.Verbosity.VERBOSE: logging.Formatter(
f"%(levelname)-8s %(funcName)-{stm32pio.settings.log_fieldwidth_function}s %(message)s")
})
projects_logger_handler.setFormatter(formatter)
projects_logger.addHandler(projects_logger_handler)
verbose_setter(settings.get('verbose')) # set initial verbosity settings based on the saved state
settings.beginGroup('app')
restored_projects_paths: List[str] = []
for index in range(settings.beginReadArray('projects')):
settings.setArrayIndex(index)
restored_projects_paths.append(settings.value('path'))
settings.endArray()
settings.endGroup()