@@ -0,0 +1,2283 @@
+# -*- coding: utf-8 -*-%0A# !/usr/bin/python%0A################################### PART0 DESCRIPTION #################################%0A# Filename: decorator_of_function.py%0A# Description:%0A#%0A%0A# Author: Shuai Yuan%0A# E-mail: ysh329@sina.com%0A# Create: 2016-02-18 11:34:27%0A# Last:%0A__author__ = 'yuens'%0A%0A################################### PART1 IMPORT ######################################%0Aimport logging%0Aimport time%0A%0A################################### PART2 CLASS && FUNCTION ###########################%0Aclass CreateDecorator(object):%0A    def __init__(self):%0A        self.start = time.clock()%0A%0A        logging.basicConfig(level = logging.INFO,%0A                  format = '%25(asctime)s  %25(levelname)5s %25(filename)19s%5Bline:%25(lineno)3d%5D %25(funcName)s %25(message)s',%0A                  datefmt = '%25y-%25m-%25d %25H:%25M:%25S',%0A                  filename = './my-first-cnn.log',%0A                  filemode = 'a')%0A        console = logging.StreamHandler()%0A        console.setLevel(logging.INFO)%0A%0A        formatter = logging.Formatter('%25(asctime)s  %25(levelname)5s %25(filename)19s%5Bline:%25(lineno)3d%5D %25(funcName)s %25(message)s')%0A        console.setFormatter(formatter)%0A%0A        logging.getLogger('').addHandler(console)%0A        logging.info(%22START CLASS %7Bclass_name%7D.%22.format(class_name = CreateDecorator.__name__))%0A%0A%0A%0A    def __del__(self):%0A        logging.info(%22END CLASS %7Bclass_name%7D.%22.format(class_name = CreateDecorator.__name__))%0A        self.end = time.clock()%0A        logging.info(%22The class %7Bclass_name%7D run time is : %7Bdelta_time%7D seconds%22.format(class_name = CreateDecorator.__name__, delta_time = self.end - self.start))%0A%0A%0A%0A    def log_of_function(self, undecorated_function):%0A        def record_start_and_end_log(args, **kw):%0A            logging.info(%22Function %7B0%7D start.%22.format(undecorated_function.__name__))%0A            n = undecorated_function(args, **kw)%0A            logging.info(%22Function %7B0%7D end.%22.format(undecorated_function.__name__))%0A            return n%0A        return record_start_and_end_log%0A%0A'''%0ADecorator = CreateDecorator()%0A@Decorator.log_of_function%0Adef fun_a(n):%0A    logging.info(%22This is %7B0%7D from function a.%22.format(n))%0A    return n%0A'''''%0A################################### PART3 CLASS TEST ##################################%0A'''%0An = fun_a(11)%0Alogging.info(%22n is %7B0%7D%22.format(n))%0A'''

Add class file "decorator_of_function.py".