Set up CASA to write log messages to standard output.

    filter
      The log level filter: less urgent messages will not be shown. Valid values
      are strings: "DEBUG1", "INFO5", ... "INFO1", "INFO", "WARN", "SEVERE".

    This function creates and returns a CASA ”log sink” object that is
    configured to write to standard output. The default CASA implementation
    would *always* create a file named ``casapy.log`` in the current
    directory; this function safely prevents such a file from being left
    around. This is particularly important if you don’t have write permissions
    to the current directory.

def logger(filter='WARN'):
    """Set up CASA to write log messages to standard output.

    filter
      The log level filter: less urgent messages will not be shown. Valid values
      are strings: "DEBUG1", "INFO5", ... "INFO1", "INFO", "WARN", "SEVERE".

    This function creates and returns a CASA ”log sink” object that is
    configured to write to standard output. The default CASA implementation
    would *always* create a file named ``casapy.log`` in the current
    directory; this function safely prevents such a file from being left
    around. This is particularly important if you don’t have write permissions
    to the current directory.

    """
    import os, shutil, tempfile

    cwd = os.getcwd()
    tempdir = None

    try:
        tempdir = tempfile.mkdtemp(prefix='casautil')

        try:
            os.chdir(tempdir)
            sink = tools.logsink()
            sink.setlogfile(sanitize_unicode(os.devnull))
            try:
                os.unlink('casapy.log')
            except OSError as e:
                if e.errno != 2:
                    raise
                # otherwise, it's a ENOENT, in which case, no worries.
        finally:
            os.chdir(cwd)
    finally:
        if tempdir is not None:
            shutil.rmtree(tempdir, onerror=_rmtree_error)

    sink.showconsole(True)
    sink.setglobal(True)
    sink.filter(sanitize_unicode(filter.upper()))
    return sink