Changeset 435


Ignore:
Timestamp:
18.08.2011 18:25:31 (8 years ago)
Author:
marcus
Message:

Logging system replies on messaging system (pubsub).

Location:
SHX/trunk/SeismicHandler
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • SHX/trunk/SeismicHandler/core/__init__.py

    r294 r435  
    2323from SeismicHandler.modules.traces import Traces as sh_traces 
    2424from SeismicHandler.modules.history import History as history 
    25 from SeismicHandler.modules.log import getLogger 
    2625 
    2726from obspy.core import read as obspy_read 
  • SHX/trunk/SeismicHandler/modules/log.py

    r294 r435  
    2424from SeismicHandler.basics import Singleton 
    2525from SeismicHandler.config import Settings 
     26from SeismicHandler.utils.pubsub import pub as msgs 
    2627 
    2728import logging 
     
    99100        atexit.register(self.shutdown) 
    100101 
     102        msgs.subscribe(self.receiveMessages, 'log') 
     103 
    101104    def shutdown(self): 
    102105        """Move our logfile to backup destination for later checking. 
     
    117120        return logging.getLogger(name) 
    118121 
    119 def getLogger(name): 
    120     """ 
    121     Helper function for initializing a new logger instance. 
    122     """ 
    123     return Logging().newLogger(name) 
     122    def receiveMessages(self, msg, topic=msgs.AUTO_TOPIC): 
     123        """ 
     124        Subscribed to MessageSystem. 
     125        """ 
     126        try: 
     127            mode = topic.getNameTuple()[1] 
     128        except: 
     129            return 
     130 
     131        try: 
     132            id = ".".join(topic.getNameTuple()[2:]) 
     133        except: 
     134            id = "main" 
     135 
     136        l = logging.getLogger(id) 
     137 
     138        try: 
     139            logger = getattr(l, mode) 
     140            logger(msg) 
     141        except: 
     142            raise ValueError("Unknown logging mode '%s'!" % mode) 
     143 
     144# logging system is always initialized 
     145Logging() 
    124146 
    125147if __name__ == "__main__": 
    126     a = Logging().newLogger("test") 
    127     a.info("info") 
    128     a.error("error") 
    129     a.debug("debug") 
     148    msgs.sendMessage('log.info', msg='Log Info Message') 
     149    msgs.sendMessage('log.error', msg='Log Error Message') 
     150    msgs.sendMessage('log.debug', msg='Log Debug Message') 
     151    msgs.sendMessage('log.debug.traces.test', 
     152                                      msg='Log Debug Message in "traces.test"') 
  • SHX/trunk/SeismicHandler/modules/parse.py

    r294 r435  
    3131import re 
    3232import inspect 
    33 import SeismicHandler.core as shcore 
    3433import SeismicHandler.commands as commands 
    3534from SeismicHandler.basics import AttribDict 
Note: See TracChangeset for help on using the changeset viewer.