def get_val(dic, key, default=None):
    """
    Traverse through the levels of a dictionary to obtain the
    specified key, safely handling any missing levels.  For example, if the
    key is "app.error", it will find the "error" entry in the "app"
    dictionary; if either the app dictionary or the error entry is missing,
    then the default will be returned.
    """
    if not key:
        return default

    try:
        current = dic
        for attribute in key.split("."):
            current = current[attribute]
        return current

    except KeyError:
        return default