Here is a small function to log to a local file in python, I use it all the time.

#  py:2.7, 3.5
def get_local_logger():
    """
    Log to local .log file
    """

    logger = logging.getLogger(__file__)
    hdlr = logging.FileHandler(__file__ + '.log')
    
    time_name_fmt = '%(asctime)s|%(name)s|%(filename)s'
    log_detail_fmt = ':%(lineno)s|%(levelname)s|%(message)s'
    logging_format = time_name_fmt + log_detail_fmt

    formatter = logging.Formatter(logging_format)
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    logger.setLevel(logging.INFO)

    return logger
>> local_logger = get_local_logger()
>> local_logger.INFO("Logging to local file!")

January 1, 2016 python


Previous post
Joining URL Paths When you want to join an absolute url path http://domain.com with a relative path /authenticate changes are you’d want do something like this
Next post
Multi Item Import Here is a clean way to import multiple items from the same module