import logging


def _get_filehandler_with_formatter(logname, formatter=None):
    """ Return a logging FileHandler for given logname using a given
    logging formatter
    :param logname: Name of the file where logs will be stored, ".log"
    extension will be added
    :param formatter: An instance of logging.Formatter or None if the default
    should be used
    :return:
    """
    handler = logging.FileHandler(logname)
    if formatter is not None:
        handler.setFormatter(formatter)
    return handler