PokeyWorks.setup_logger()

#****************************** Logging ********************************

#***********************************************************************
#               Default logging configuration settings
#               https://docs.python.org/2/library/logging.html#logger-objects
#***********************************************************************

def setup_logger(name, level, lpath='./tmp/last_run.log'):

        # Get the logger and set the level
        logger = logging.getLogger(name)
        logger.setLevel(level)

        # Create the formatters
        file_formatter = logging.Formatter('%(asctime)s | %(levelname)s | %(module)s >> %(message)s')
        cons_formatter = logging.StreamHandler('%(message)s')

        # Create the handlers
        cons_handler = logging.StreamHandler(sys.stdout)
        cons_handler.setFormatter(cons_formatter)
        logger.addHandler(cons_handler)

        if level==logging.DEBUG:
                # Includes current run information if level = logging.DEBUG
                f=open(resource_path(lpath),'w+')
                f.close()

                last_run = logging.FileHandler(resource_path(lpath), 'w')
                last_run.setFormatter(file_formatter)
                logger.addHandler(last_run)

        return logger