# Buggy code
def init_logging(
    settings,
    use_logging_file=True,
    logging_file=None,
    default_config=None,
    debug=False,
    verbosity=0,
    uncaught_logger=None,
    uncaught_handler=None,
):
    """Sets up logging."""

    import os

    from octoprint.util import dict_merge

    # default logging configuration
    if default_config is None:
        default_config = {
            "version": 1,
            "formatters": {
                "simple": {
                    "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
                },
                "serial": {"format": "%(asctime)s - %(message)s"},
            },
            "handlers": {
                "console": {
                    "class": "logging.StreamHandler",
                    "level": "DEBUG",
                    "formatter": "simple",
                    "stream": "ext://sys.stdout",
                },
                "file": {
                    "class": "octoprint.logging.handlers.CleaningTimedRotatingFileHandler",
                    "level": "DEBUG",
                    "formatter": "simple",
                    "when": "D",
                    "backupCount": 6,
                    "filename": os.path.join(
                        settings.getBaseFolder("logs"), "octoprint.log"
                    ),
                },
                "serialFile": {
                    "class": "octoprint.logging.handlers.SerialLogHandler",
                    "level": "DEBUG",
                    "formatter": "serial",
                    "backupCount": 3,
                    "filename": os.path.join(
                        settings.getBaseFolder("logs"), "serial.log"
                    ),
                },
            },
            "loggers": {
                "SERIAL": {
                    "level": "CRITICAL",
                    "handlers": ["serialFile"],
                    "propagate": False,
                },
                "octoprint": {"level": "INFO"},
                "octoprint.util": {"level": "INFO"},
                "octoprint.plugins": {"level": "INFO"},
            },
            "root": {"level": "WARN", "handlers": ["console", "file"]},
        }

    if debug or verbosity > 0:
        default_config["loggers"]["octoprint"]["level"] = "DEBUG"
        default_config["root"]["level"] = "INFO"
    if verbosity > 1:
        default_config["loggers"]["octoprint.plugins"]["level"] = "DEBUG"
    if verbosity > 2:
        default_config["root"]["level"] = "DEBUG"

    if use_logging_file:
        # further logging configuration from file...
        if logging_file is None:
            logging_file = os.path.join(settings.getBaseFolder("base"), "logging.yaml")

        config_from_file = {}
        if os.path.exists(logging_file) and os.path.isfile(logging_file):
            import yaml

            with open(logging_file, "r") as f:
                config_from_file = yaml.safe_load(f)

        # we merge that with the default config
        config = dict_merge(default_config, config_from_file)
    else:
        config = default_config

    # configure logging globally
    return set_logging_config(
        config, debug, verbosity, uncaught_logger, uncaught_handler
    )


# Traceback (TypeError)
Traceback (most recent call last):
  File "/home/pi/oprint/bin/octoprint", line 9, in <module>
    load_entry_point('OctoPrint==1.2.16', 'console_scripts', 'octoprint')()
  File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.2.16-py2.7.egg/octoprint/__init__.py", line 94, in main
    octoprint.run()
  File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.2.16-py2.7.egg/octoprint/server/__init__.py", line 177, in run
    self._setup_logging(self._debug, self._logConf)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.2.16-py2.7.egg/octoprint/server/__init__.py", line 627, in _setup_logging
    logging.config.dictConfig(config)
  File "/usr/lib/python2.7/logging/config.py", line 794, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/lib/python2.7/logging/config.py", line 371, in __init__
    self.config = ConvertingDict(config)
TypeError: 'NoneType' object is not iterable

# Fixed code
def init_logging(
    settings,
    use_logging_file=True,
    logging_file=None,
    default_config=None,
    debug=False,
    verbosity=0,
    uncaught_logger=None,
    uncaught_handler=None,
):
    """Sets up logging."""

    import os

    from octoprint.util import dict_merge

    # default logging configuration
    if default_config is None:
        default_config = {
            "version": 1,
            "formatters": {
                "simple": {
                    "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
                },
                "serial": {"format": "%(asctime)s - %(message)s"},
            },
            "handlers": {
                "console": {
                    "class": "logging.StreamHandler",
                    "level": "DEBUG",
                    "formatter": "simple",
                    "stream": "ext://sys.stdout",
                },
                "file": {
                    "class": "octoprint.logging.handlers.CleaningTimedRotatingFileHandler",
                    "level": "DEBUG",
                    "formatter": "simple",
                    "when": "D",
                    "backupCount": 6,
                    "filename": os.path.join(
                        settings.getBaseFolder("logs"), "octoprint.log"
                    ),
                },
                "serialFile": {
                    "class": "octoprint.logging.handlers.SerialLogHandler",
                    "level": "DEBUG",
                    "formatter": "serial",
                    "backupCount": 3,
                    "filename": os.path.join(
                        settings.getBaseFolder("logs"), "serial.log"
                    ),
                },
            },
            "loggers": {
                "SERIAL": {
                    "level": "CRITICAL",
                    "handlers": ["serialFile"],
                    "propagate": False,
                },
                "octoprint": {"level": "INFO"},
                "octoprint.util": {"level": "INFO"},
                "octoprint.plugins": {"level": "INFO"},
            },
            "root": {"level": "WARN", "handlers": ["console", "file"]},
        }

    if debug or verbosity > 0:
        default_config["loggers"]["octoprint"]["level"] = "DEBUG"
        default_config["root"]["level"] = "INFO"
    if verbosity > 1:
        default_config["loggers"]["octoprint.plugins"]["level"] = "DEBUG"
    if verbosity > 2:
        default_config["root"]["level"] = "DEBUG"

    config = default_config
    if use_logging_file:
        # further logging configuration from file...
        if logging_file is None:
            logging_file = os.path.join(settings.getBaseFolder("base"), "logging.yaml")

        config_from_file = {}
        if os.path.exists(logging_file) and os.path.isfile(logging_file):
            import yaml

            with open(logging_file, "r") as f:
                config_from_file = yaml.safe_load(f)

        # we merge that with the default config
        if config_from_file is not None and isinstance(config_from_file, dict):
            config = dict_merge(default_config, config_from_file)

    # configure logging globally
    return set_logging_config(
        config, debug, verbosity, uncaught_logger, uncaught_handler
    )