def getLog(filename = "stderr", level = 0, trace = 0):
    if filename is None:
        return NullLog(None, 0)
    path = os.path.dirname(filename)
    # be nice and figure out the permission problems if we're working
    # with a real path
    if path:
        if not os.path.exists(path):
            printErr("ERROR: Invalid pathname for logfile: %s" % (path,))
            filename = "stderr"
        if os.path.exists(filename):
            if not os.access(filename, os.W_OK):
                printErr("ERROR: Could not open log file %s for writing" % (
                    filename,))
                filename = "stderr"
        elif not os.access(path, os.W_OK|os.X_OK):
            printErr("ERROR: could not create logfile %s"
                     "due to directory permissions" % (filename,))
            filename = "stderr"
    # all should be sane now
    if trace:
        return TraceLog(filename, level)
    return FileLog(filename, level)


# initialize the module global log
dataset/ETHPy150Open sassoftware/conary/conary/lib/tracelog.py/getLog/original