def init_base_logging(directory="./log", verbose=0, silent=False, color=False, no_file=False,
                      truncate=True, config_location=None):
    """
    Initialize the Icetea logging by creating a directory to store logs
    for this run and initialize the console logger for Icetea itself.

    :param directory: Directory where to store the resulting logs
    :param verbose: Log level as integer
    :param silent: Log level warning
    :param no_file: Log to file
    :param color: Log coloring
    :param truncate: Log truncating
    :param config_location: Location of config file.
    :raises IOError if unable to read configuration file.
    :raises OSError if log path already exists.
    :raises ImportError if colored logging was requested but coloredlogs module is not installed.
    """
    global LOGPATHDIR
    global STANDALONE_LOGGING
    global TRUNCATE_LOG
    global COLOR_ON
    global SILENT_ON
    global VERBOSE_LEVEL

    if config_location:
        try:
            _read_config(config_location)
        except IOError as error:
            raise IOError("Unable to read from configuration file {}: {}".format(config_location,
                                                                                 error))
        except jsonschema.SchemaError as error:
            raise jsonschema.SchemaError("Logging configuration schema "
                                         "file malformed: {}".format(error))

    LOGPATHDIR = os.path.join(directory, datetime.datetime.now().strftime(
        "%Y-%m-%d_%H%M%S.%f").rstrip("0"))

    # Initialize the simple console logger for IceteaManager
    icetealogger = logging.getLogger("icetea")
    icetealogger.propagate = False
    icetealogger.setLevel(logging.DEBUG)
    stream_handler = logging.StreamHandler()
    formatter = BenchFormatter(LOGGING_CONFIG.get("IceteaManager").get("format"),
                               LOGGING_CONFIG.get("IceteaManager").get("dateformat"))
    if not color:
        stream_handler.setFormatter(formatter)
    elif color and not COLORS:
        raise ImportError("Missing coloredlogs module. Please install with "
                          "pip to use colors in logging.")
    else:

        class ColoredBenchFormatter(coloredlogs.ColoredFormatter):
            """
            This is defined as an internal class here because coloredlogs is and optional
            dependency.
            """
            converter = datetime.datetime.fromtimestamp

            def formatTime(self, record, datefmt=None):
                date_and_time = self.converter(record.created, tz=pytz.utc)
                if "%F" in datefmt:
                    msec = "%03d" % record.msecs
                    datefmt = datefmt.replace("%F", msec)
                str_time = date_and_time.strftime(datefmt)
                return str_time

        COLOR_ON = color
        stream_handler.setFormatter(ColoredBenchFormatter(
            LOGGING_CONFIG.get("IceteaManager").get("format"),
            LOGGING_CONFIG.get("IceteaManager").get("dateformat"),
            LEVEL_FORMATS, FIELD_STYLES))

    SILENT_ON = silent
    VERBOSE_LEVEL = verbose
    if not no_file:
        try:
            os.makedirs(LOGPATHDIR)
        except OSError:
            raise OSError("Log path %s already exists." % LOGPATHDIR)
        filename = LOGGING_CONFIG.get("IceteaManager").get("file").get("name", "icetea.log")
        icetealogger = _add_filehandler(icetealogger, get_base_logfilename(filename),
                                        formatter, "IceteaManager")
    if verbose and not silent:
        stream_handler.setLevel(logging.DEBUG)
    elif silent:
        stream_handler.setLevel(logging.WARN)
    else:
        stream_handler.setLevel(getattr(logging, LOGGING_CONFIG.get("IceteaManager").get("level")))
    icetealogger.addHandler(stream_handler)
    TRUNCATE_LOG = truncate
    if TRUNCATE_LOG:
        icetealogger.addFilter(ContextFilter())
    STANDALONE_LOGGING = False
def init_base_logging ( directory = "./log" , verbose = 0 , silent = False , color = False , no_file = False , truncate = True , config_location = None ) : global LOGPATHDIR global STANDALONE_LOGGING global TRUNCATE_LOG global COLOR_ON global SILENT_ON global VERBOSE_LEVEL if config_location : try : _read_config ( config_location ) except IOError as error : raise IOError ( "Unable to read from configuration file {}: {}" . format ( config_location , error ) ) except jsonschema . SchemaError as error : raise jsonschema . SchemaError ( "Logging configuration schema " "file malformed: {}" . format ( error ) ) LOGPATHDIR = os . path . join ( directory , datetime . datetime . now ( ) . strftime ( "%Y-%m-%d_%H%M%S.%f" ) . rstrip ( "0" ) ) icetealogger = logging . getLogger ( "icetea" ) icetealogger . propagate = False icetealogger . setLevel ( logging . DEBUG ) stream_handler = logging . StreamHandler ( ) formatter = BenchFormatter ( LOGGING_CONFIG . get ( "IceteaManager" ) . get ( "format" ) , LOGGING_CONFIG . get ( "IceteaManager" ) . get ( "dateformat" ) ) if not color : stream_handler . setFormatter ( formatter ) elif color and not COLORS : raise ImportError ( "Missing coloredlogs module. Please install with " "pip to use colors in logging." ) else : class ColoredBenchFormatter ( coloredlogs . ColoredFormatter ) : converter = datetime . datetime . fromtimestamp def formatTime ( self , record , datefmt = None ) : date_and_time = self . converter ( record . created , tz = pytz . utc ) if "%F" in datefmt : msec = "%03d" % record . msecs datefmt = datefmt . replace ( "%F" , msec ) str_time = date_and_time . strftime ( datefmt ) return str_time COLOR_ON = color stream_handler . setFormatter ( ColoredBenchFormatter ( LOGGING_CONFIG . get ( "IceteaManager" ) . get ( "format" ) , LOGGING_CONFIG . get ( "IceteaManager" ) . get ( "dateformat" ) , LEVEL_FORMATS , FIELD_STYLES ) ) SILENT_ON = silent VERBOSE_LEVEL = verbose if not no_file : try : os . makedirs ( LOGPATHDIR ) except OSError : raise OSError ( "Log path %s already exists." % LOGPATHDIR ) filename = LOGGING_CONFIG . get ( "IceteaManager" ) . get ( "file" ) . get ( "name" , "icetea.log" ) icetealogger = _add_filehandler ( icetealogger , get_base_logfilename ( filename ) , formatter , "IceteaManager" ) if verbose and not silent : stream_handler . setLevel ( logging . DEBUG ) elif silent : stream_handler . setLevel ( logging . WARN ) else : stream_handler . setLevel ( getattr ( logging , LOGGING_CONFIG . get ( "IceteaManager" ) . get ( "level" ) ) ) icetealogger . addHandler ( stream_handler ) TRUNCATE_LOG = truncate if TRUNCATE_LOG : icetealogger . addFilter ( ContextFilter ( ) ) STANDALONE_LOGGING = False
Initialize the Icetea logging by creating a directory to store logs
    for this run and initialize the console logger for Icetea itself.

    :param directory: Directory where to store the resulting logs
    :param verbose: Log level as integer
    :param silent: Log level warning
    :param no_file: Log to file
    :param color: Log coloring
    :param truncate: Log truncating
    :param config_location: Location of config file.
    :raises IOError if unable to read configuration file.
    :raises OSError if log path already exists.
    :raises ImportError if colored logging was requested but coloredlogs module is not installed.