Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

socketLogging.py

00001 #!/usr/local/bin/python
00002 #
00003 #                               Copyright 2002
00004 #                                     by
00005 #                        The Board of Trustees of the
00006 #                     Leland Stanford Junior University.
00007 #                            All rights reserved.
00008 #
00009 
00010 __facility__ = "Online"
00011 __abstract__ = "GLAST LAT Alert System GUI"
00012 __author__   = "J. Panetta"
00013 __date__     = "28/01/2005"
00014 __version__  = "$Revision: 1.2 $"
00015 __credits__  = "SLAC"
00016 
00017 import LATTE.copyright_SLAC
00018 import logging
00019 import logging.handlers
00020 import sys
00021 ALARM_TCP_LOGGING_PORT    = 9099
00022 
00023 class MyLogSocketHandler(logging.handlers.SocketHandler):
00024   def __init__(self, *args):
00025     apply(logging.handlers.SocketHandler.__init__, (self,) + args)
00026 
00027   def handleError(self, record):
00028     if self.closeOnError and self.sock:
00029       self.sock.shutdown(2)
00030       self.sock.close()
00031       self.sock = None        #try to reconnect next time
00032     else:
00033       raise IOError, sys.exc_info()[1]
00034       
00035   def createSocket(self):
00036     """Override base classes createSocket method.  
00037        This isn't allowed to fail silently
00038     """
00039     self.sock = self.makeSocket()
00040     
00041 def socketLogging(logHost, logLevel, port=ALARM_TCP_LOGGING_PORT):
00042    
00043   logging.root.setLevel(logging.__dict__[logLevel])
00044   
00045   # set up the socket handler for this logger
00046   sockHdlr   = MyLogSocketHandler(logHost, port)
00047 
00048   fmt = logging.Formatter("%(asctime)s %(filename)s:%(lineno)d %(levelname)-5s - %(message)s")
00049   sockHdlr.setFormatter(fmt)
00050   logging.getLogger().addHandler(sockHdlr)
00051   
00052   try:
00053     logging.info('Trying to connect to the message logger')
00054   except Exception, e:
00055     logging.getLogger("").removeHandler(sockHdlr)
00056     logging.fatal("Can't connect to the message logger, Aborting job")
00057     raise
00058   else:
00059     logging.info('Successfully connected to the message logger')
00060   

Generated on Fri Jul 21 13:26:32 2006 for LATTE R04-12-00 by doxygen 1.4.3