def log(function):
        """Logger that records which phase processes each token"""
        type_names = dict((value, key) for key, value in 
                          constants.tokenTypes.iteritems())
        def wrapped(self, *args, **kwargs):
            if function.__name__.startswith("process") and len(args) > 0:
                token = args[0]
                try:
                    info = {"type":type_names[token['type']]}
                except:
                    raise
                if token['type'] in constants.tagTokenTypes:
                    info["name"] = token['name']

                self.parser.log.append((self.parser.tokenizer.state.__name__,
                                        self.parser.phase.__class__.__name__, 
                                        self.__class__.__name__, 
                                        function.__name__, 
                                        info))
                return function(self, *args, **kwargs)
            else:
                return function(self, *args, **kwargs)
        return wrapped
Logger that records which phase processes each token
html5lib/html5parser.py