Write a python function to accept user defined file, user-defined loglevel and create a file-based and invoke the user-defined function with this logger.


Topic: Write a python function to accept user defined file, user-defined loglevel and create a file-based and invoke the user-defined function with this logger.

Solution

import logging
def create_logging_level(user_func, user_filename, user_loglevel):
    logger = logging.getLogger('simple_example')
    logger.setLevel(user_loglevel)
    ch = logging.FileHandler(user_filename)
    ch.setLevel(user_loglevel)
    logger.addHandler(ch)
    if callable(user_func):
        user_func(logger)



List all Python Programs