'Context manager to temporarily log messages to a file.
Parameters
filename : str
The file to log messages to.
filter_level : str
If set, any log messages less important than ``filter_level`` will
not be output to the file. Note that this is in addition to the
top-level filtering for the logger, so if the logger has level
\'INFO\', then setting ``filter_level`` to ``INFO`` or ``DEBUG``
will have no effect, since these messages are already filtered
out.
filter_origin : str
If set, only log messages with an origin starting with
``filter_origin`` will be output to the file.
Notes
By default, the logger already outputs log messages to a file set in
the Astropy configuration file. Using this context manager does not
stop log messages from being output to that file, nor does it stop log
messages from being printed to standard output.
Examples
The context manager is used as::
with logger.log_to_file(\'myfile.log\'):
# your code here'

@contextmanager
def log_to_file(self, filename, filter_level=None, filter_origin=None):

    fh = logging.FileHandler(filename)
    if (filter_level is not None):
        fh.setLevel(filter_level)
    if (filter_origin is not None):
        fh.addFilter(FilterOrigin(filter_origin))
    f = logging.Formatter(conf.log_file_format)
    fh.setFormatter(f)
    self.addHandler(fh)
    (yield)
    fh.close()
    self.removeHandler(fh)
