def pcs_logger(filePathName='%s/data/%s/%s.log' % (gv.logLocation, getpass.getuser(), getpass.getuser()), _logger='',
               name='pcsLogger', fresh=0):
    """
    SYNOPSIS: Creates nice logger. Will nuke FileHandler logger of similar
                type if filePathName is different from existing loggers

    INPUTS
     (string) 	filePathName:	path and file name of FileHandler stream
     (logging.Logger)	logger:	python or pymel logger object
     (string) 			name:	'handle' to logger object
     (bool) 			fresh:	1 = tries to delete old log file

    RETURNS: (logging.Logger) logger object
    """

    # create dir if doesn't exist
    filePathName = filePathName.replace('\\', '/')
    filePath = filePathName[:filePathName.rfind('/')]
    if not os.path.exists(filePath):
        os.makedirs(filePath)

    # delete file if already exists
    if fresh:
        try:
            if os.path.exists(filePathName):
                os.remove(filePathName)
        except RuntimeError:
            print ("'%s' still opened, skipping deletion" % filePathName)

    # use our logger	# Not needed w/ pymelLogger
    logging.setLoggerClass(PCSlogging)

    if not isinstance(_logger, logging.Logger):
        _logger = logging.getLogger(name)
    else:
        name = _logger.name

    # turn off Exceptions?
    logging.raiseExceptions = 1

    # create file format
    if sys.version_info[1] >= 5:
        # python 2.6 allows function name in logging
        formatter = logging.Formatter('%(asctime)s, %(module)s, %(funcName)s, %(lineno)d, %(levelname)s, %(message)s')
    else:
        formatter = logging.Formatter('%(asctime)s, %(lineno)d, %(levelname)s, %(message)s')

    # determine if handler has been made
    makeNewFileHandler = 1
    makeNewSMTPHandler = 1
    smtpHandlerFound = 0
    if len(_logger.handlers):
        for hndlr in map(lambda x: x, _logger.handlers):
            if hndlr.__class__ == logging.FileHandler:
                if not hndlr.stream.closed:
                    if hndlr.stream.name == filePathName:
                        makeNewFileHandler = 0
                    else:
                        deleteHandler(_logger.handlers, hndlr)
                else:
                    deleteHandler(_logger.handlers, hndlr)
            elif smtpHandlerFound and hndlr.__class__ == logging.handlers.SMTPHandler:
                deleteHandler(_logger.handlers, hndlr)
            else:
                smtpHandlerFound = 1
                makeNewSMTPHandler = 0

    # Make fileHandler and email handler
    if makeNewFileHandler:
        hdlr = logging.FileHandler(filePathName)
        #hdlr = logging.handlers.RotatingFileHandler(filePathName, 'a', 500, 2)
        hdlr.setFormatter(formatter)
        _logger.addHandler(hdlr)

    # Make email handler
    if makeNewSMTPHandler:
        userName = getpass.getuser()
        sHdlr = logging.handlers.SMTPHandler(MAILHOST, '%s%s' % (userName, FROMADDRESS), toAddresses,
                                             '%s: Critical from %s' % (name, userName))
        sHdlr.setLevel(logging.CRITICAL)
        _logger.addHandler(sHdlr)

    # set default level
    _logger.setLevel(logging.INFO)

    return _logger
dataset/ETHPy150Open CountZer0/PipelineConstructionSet/python/common/diagnostic/pcsLogger.py/pcs_logger/original