import logging


def get_log_stream(logger):
    """
    Returns a log stream.
    If there is a file handler this stream will be used.
    If there is no logfile return the stderr log stream
    
    Returns:
        A stream to the root log file or stderr stream.
    """
    
    file_stream = None
    log_stream = None
    for handler in logger.handlers:
        if isinstance(handler, logging.FileHandler):
            file_stream = handler.stream
        else:
            log_stream = handler.stream
    
    if file_stream:
        return file_stream
    
    return log_stream