Ejemplo n.º 1
0
def initLogging(verbosity=0, name="SCOOP"):
    """Creates a logger."""
    global loggingConfig

    verbose_levels = {-2: "CRITICAL", -1: "ERROR", 0: "WARNING", 1: "INFO", 2: "DEBUG", 3: "DEBUG", 4: "NOSET"}
    log_handlers = {
        "console": {
            "class": "logging.StreamHandler",
            "formatter": "{name}Formatter".format(name=name),
            "stream": "ext://sys.stdout",
        }
    }
    loggingConfig.update(
        {"{name}Logger".format(name=name): {"handlers": ["console"], "level": verbose_levels[verbosity]}}
    )
    dict_log_config = {
        "version": 1,
        "handlers": log_handlers,
        "loggers": loggingConfig,
        "formatters": {
            "{name}Formatter".format(name=name): {
                "format": "[%(asctime)-15s] %(module)-9s " "%(levelname)-7s %(message)s"
            }
        },
    }
    dictConfig(dict_log_config)
    return logging.getLogger("{name}Logger".format(name=name))
Ejemplo n.º 2
0
def initLogging(verbosity=0, name="SCOOP"):
        """Creates a logger."""
        global loggingConfig

        verbose_levels = {
            -2: "CRITICAL",
            -1: "ERROR",
            0: "WARNING",
            1: "INFO",
            2: "DEBUG",
            3: "NOSET",
        }
        log_handlers = {
            "console":
            {
                "class": "logging.StreamHandler",
                "formatter": "{name}Formatter".format(name=name),
                "stream": "ext://sys.stdout",
            },
        }
        loggingConfig.update({
            "{name}Logger".format(name=name):
            {
                "handlers": ["console"],
                "level": verbose_levels[verbosity],
            },
        })
        dict_log_config = {
            "version": 1,
            "handlers": log_handlers,
            "loggers": loggingConfig,
            "formatters":
            {
                "{name}Formatter".format(name=name):
                {
                    "format": "[%(asctime)-15s] %(module)-9s "
                              "%(levelname)-7s %(message)s",
                },
            },
        }
        dictConfig(dict_log_config)
        return logging.getLogger("{name}Logger".format(name=name))