Changeset 494:edbf2d4d41db

Show
Ignore:
Timestamp:
10/14/08 13:59:19 (3 months ago)
Author:
Brian Warner <warner@allmydata.com>
branch:
default
Message:

incident classifiers: change the function signature, now it just takes a trigger dict

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ChangeLog

    r493 r494  
    112008-10-14  Brian Warner  <warner@allmydata.com> 
     2 
     3        * foolscap/logging/gatherer.py 
     4        (IncidentGathererService.classify_incident): change the classifier 
     5        function signature: now it just takes a single 'trigger' dict. 
     6        * foolscap/test/test_logging.py: update to match 
     7        * doc/logging.xhtml (gatherer): same 
    28 
    39        * foolscap/logging/gatherer.py 
     
    612        them as plugins with classification functions. 
    713        (INCIDENT_GATHERER_TACFILE): update example text to match 
     14 
    815        * foolscap/test/test_logging.py (IncidentGatherer): test it 
    916        (Gatherer.test_wrongdir): exercise another error case 
  • doc/logging.xhtml

    r493 r494  
    898898starts.</p> 
    899899 
    900 <p>The <code>classify_incident()</code> function will accept a triggering 
    901 event and a pathname (from which preceding log events can be extracted, if 
    902 desired), and should return a list of categories. Each incident can wind up 
    903 in multiple categories. If no function finds a category for the incident, it 
    904 will be added to the "unknown" category. All incidents are added to the "all" 
    905 category.</p> 
     900<p>The <code>classify_incident()</code> function will accept a single 
     901triggering event (a regular log Event dictionary, see logfiles.xhtml for 
     902details, which can be examined as follows:</p> 
     903 
     904<pre class="python"> 
     905def classify_incident(trigger): 
     906    m = trigger.get('message', '') 
     907    if "Tub.connectorFinished:" in m: 
     908        return 'foolscap-tubconnector' 
     909</pre> 
     910 
     911<p>The function should return a list (or set) of categories, or a single 
     912category string, or None. Each incident can wind up in multiple categories. 
     913If no function finds a category for the incident, it will be added to the 
     914"unknown" category. All incidents are added to the "all" category.</p> 
    906915 
    907916<p>The <code>classified/</code> directory will contain a file for each 
  • foolscap/logging/gatherer.py

    r493 r494  
    511511        categories = set() 
    512512        for f in self.classifiers: 
    513             c = f(tubid_s, incident) 
     513            (header, events) = incident 
     514            trigger = header["trigger"] 
     515            c = f(trigger) 
    514516            if c: # allow the classifier to return None, or [], or ["foo"] 
    515517                if isinstance(c, str): 
     
    553555# import re 
    554556# TUBCON_RE = re.compile(r'^Tub.connectorFinished: WEIRD, <foolscap.negotiate.TubConnector instance at \w+> is not in \[') 
    555 # def classify_incident(nodeid_s, incident): 
     557# def classify_incident(trigger): 
    556558#     # match some foolscap messages 
    557 #     (header, events) = incident 
    558 #     trigger = header['trigger'] 
    559559#     m = trigger.get('message', '') 
    560560#     if TUBCON_RE.search(m): 
  • foolscap/test/test_logging.py

    r493 r494  
    10121012        d.addCallback(lambda res: ig.disownServiceParent()) 
    10131013 
    1014         def classify_boom(nodeid_s, (header,events)): 
    1015             if "boom" in header["trigger"].get("message",""): 
     1014        def classify_boom(trigger): 
     1015            if "boom" in trigger.get("message",""): 
    10161016                return "boom" 
    1017         def classify_foom(nodeid_s, (header,events)): 
    1018             if "foom" in header["trigger"].get("message",""): 
     1017        def classify_foom(trigger): 
     1018            if "foom" in trigger.get("message",""): 
    10191019                return "foom" 
    10201020 
     
    10291029            f = open(foomfile, "w") 
    10301030            f.write(''' 
    1031 def classify_incident(nodeid_s, (header,events)): 
    1032     if "foom" in header["trigger"].get("message",""): 
     1031def classify_incident(trigger): 
     1032    if "foom" in trigger.get("message",""): 
    10331033        return "foom" 
    10341034''')