Changeset 184:8c6eaaf8908a

Show
Ignore:
Timestamp:
11/28/08 15:08:22 (3 years ago)
Author:
chris@…
Branch:
unix
Message:

No longer use an external config file for logging

Files:
12 modified

Legend:

Unmodified
Added
Removed
  • StormSiren/AlertDevice.py

    r122 r184  
    5959                self.log = logging.getLogger('AlertDevice') 
    6060 
     61                self.log.setLevel(logging.INFO) 
    6162                self.__parse_weather_types(alerts) 
    6263                self.__parse_areas(areas) 
  • StormSiren/Config.py

    r122 r184  
    4848 
    4949class Config(object): 
    50         def __init__(self, appname, config_file = None, log_config_file = None): 
    51                 self.log                  = None 
     50        def __init__(self, appname, config_file = None): 
    5251                self.__appname            = appname 
    5352                self.__config_file        = '' 
     
    5554                self.__config_dir         = self.___getConfigDir() 
    5655                self.__config_file        = self.__config_dir + '/' + appname + '.conf' 
    57                 self.__log_config_file    = self.__config_dir + '/' + appname + '-log.conf' 
     56                self.log                  = logging.getLogger('Config') 
    5857 
    59                 if(log_config_file): 
    60                         self.__log_config_file = log_config_file 
    61  
    62                 if(os.path.exists(self.__log_config_file)): 
    63                         logging.config.fileConfig(self.__log_config_file) 
    64                 else: 
    65                         print("Log configuration file [%s] not found" % self.__log_config_file) 
    66                         print("See the example StormSiren-log.conf file in the examples directory") 
    67                         if(not os.path.exists(self.__config_dir)): 
    68                                 os.mkdir(self.__config_dir) 
    69                         sys.exit(1) 
    70  
    71                 self.log                  = logging.getLogger('Config') 
    72                 self.log.debug("Using logging configuration file %s" % self.__log_config_file) 
     58                self.log.setLevel(logging.INFO) 
    7359 
    7460                if(config_file): 
    7561                        self.__config_file = config_file 
    76                         self.log.info("Override configuration file %s" % self.__config_file) 
    7762 
    7863                if(os.path.exists(self.__config_file)): 
    7964                        self.log.debug("Using configuration file with %s" % self.__config_file) 
    80                         self.__configParser.read(self.__config_file) 
    81                         self._load() 
    8265                else: 
    8366                        self.log.error("Configuration file [%s] not found" % self.__config_file) 
     
    121104        def _load(self): 
    122105                self.log.debug("Loading Configuration File") 
     106                self.__configParser.read(self.__config_file) 
    123107 
    124108        def __str__(self): 
  • StormSiren/ExecutionAlertDevice.py

    r122 r184  
    5151                super(ExecutionAlertDevice,self).__init__(alerts,areas) 
    5252                self.__exeInfo = exeInfo 
     53                self.log = logging.getLogger('ExecutionAlertDevice') 
     54                self.log.setLevel(logging.DEBUG) 
    5355 
    5456        def display(self): 
  • StormSiren/History.py

    r122 r184  
    5757                self.log = logging.getLogger('History') 
    5858                self.modified = False 
     59 
     60                self.log.setLevel(logging.INFO) 
    5961 
    6062                # See if we can open the history file.   
  • StormSiren/JabberAlertDevice.py

    r122 r184  
    4949        pass 
    5050 
    51  
    5251from AlertDevice import * 
    5352 
     
    6160                self.__to = to 
    6261                self.a = alerts 
     62                self.log = logging.getLogger('JabberAlertDevice') 
     63 
     64                self.log.setLevel(logging.INFO) 
    6365 
    6466        def display(self): 
  • StormSiren/OsdAlertDevice.py

    r122 r184  
    6363                super(OsdAlertDevice,self).__init__(alerts,areas) 
    6464                self.__osdInfo = osdInfo 
     65                self.log = logging.getLogger('OsdAlertDevice') 
     66 
     67                self.log.setLevel(logging.INFO) 
    6568 
    6669        def display(self): 
  • StormSiren/SmsAlertDevice.py

    r122 r184  
    4747        def __init__(self, to, textwidth, smtpInfo, alerts, areas): 
    4848                super(SmsAlertDevice,self).__init__(to, textwidth, smtpInfo, alerts, areas) 
     49                self.log = logging.getLogger('SmsAlertDevice') 
     50 
     51                self.log.setLevel(logging.INFO) 
    4952         
    5053        def display(self): 
  • StormSiren/StormConfig.py

    r122 r184  
    5959 
    6060class StormConfig(Config): 
    61         def __init__(self, config_file = None, log_config_file = None): 
     61        def __init__(self, config_file = None): 
     62                super(StormConfig,self).__init__(__APPNAME__,config_file) 
     63 
    6264                self.__states          = [] 
    6365                self.devices           = [] 
    6466                self.__history_file    = '' 
     67                self.__max_history     = History.DEFAULT_MAX_HISTORICAL_EVENTS 
     68                self.__history_file    = self.config_dir + '/' + __APPNAME__ + '.history' 
    6569                self.log               = logging.getLogger('StormConfig') 
    66                 self.__max_history     = History.DEFAULT_MAX_HISTORICAL_EVENTS 
    67  
    68                 super(StormConfig,self).__init__(__APPNAME__,config_file, log_config_file) 
    69  
    70                 self.__history_file  = self.config_dir + '/' + __APPNAME__ + '.history' 
     70 
     71                self.log.setLevel(logging.INFO) 
     72 
     73                self._load() 
    7174 
    7275        def _load(self): 
     
    118121 
    119122                for i in range(1,int(num_watchers)+1): 
    120                                 dev = self.getRequired(str(i),"device") 
    121                                 alerts = self.getRequired(str(i),"alert") 
    122                                 areas = self.getRequired(str(i),"areas") 
    123  
    124                                 if(dev == "email"): 
     123                        dev = self.getRequired(str(i),"device") 
     124                        alerts = self.getRequired(str(i),"alert") 
     125                        areas = self.getRequired(str(i),"areas") 
     126                        self.log.debug("AlertDevice(%s) Areas(%s) Alerts(%s)" % (dev, alerts,areas)) 
     127 
     128                        if(dev == "email"): 
     129                                to = self.getRequired(str(i),"to") 
     130                                textwidth = int(self.get(str(i),"textwidth",-1)) 
     131                                self.devices.append(EmailAlertDevice(to,textwidth,smtpInfo,alerts,areas)) 
     132                                self.log.debug("Adding email device") 
     133                        if(dev == "sms"): 
     134                                to = self.getRequired(str(i),"to") 
     135                                textwidth = int(self.get(str(i),"textwidth",-1)) 
     136                                self.devices.append(SmsAlertDevice(to,textwidth,smtpInfo,alerts,areas)) 
     137                                self.log.debug("Adding sms device") 
     138                        if(dev == "jabber"): 
     139                                if(not jabberLoadAttempted): 
     140                                        jabber_available = self.__loadXmpp() 
     141                                        jabberLoadAttempted = True 
     142 
     143                                if(jabber_available): 
    125144                                        to = self.getRequired(str(i),"to") 
    126                                         textwidth = int(self.get(str(i),"textwidth",-1)) 
    127                                         self.devices.append(EmailAlertDevice(to,textwidth,smtpInfo,alerts,areas)) 
    128                                 if(dev == "sms"): 
    129                                         to = self.getRequired(str(i),"to") 
    130                                         textwidth = int(self.get(str(i),"textwidth",-1)) 
    131                                         self.devices.append(SmsAlertDevice(to,textwidth,smtpInfo,alerts,areas)) 
    132                                 if(dev == "jabber"): 
    133                                         if(not jabberLoadAttempted): 
    134                                                 jabber_available = self.__loadXmpp() 
    135                                                 jabberLoadAttempted = True 
    136  
    137                                         if(jabber_available): 
    138                                                 to = self.getRequired(str(i),"to") 
    139                                                 self.devices.append(JabberAlertDevice(to,jabberInfo,alerts,areas)) 
    140                                         else: 
    141                                                 self.log.error("Jabber Support Not Enabled, but Jabber Device Requested!") 
    142                                 if(dev == "osd"): 
    143                                         if(not osdLoadAttempted): 
    144                                                 osd_available = self.__loadOsd() 
    145                                                 osdLoadAttempted = True 
    146  
    147                                         if(osd_available): 
    148                                                 position = self.get(str(i),"position", DEFAULT_OSD_POSITION) 
    149                                                 alignment = self.get(str(i),"alignment", DEFAULT_OSD_ALIGNMENT) 
    150                                                 offset = int(self.get(str(i),"offset", DEFAULT_OSD_OFFSET)) 
    151                                                 timeout = int(self.get(str(i),"timeout", DEFAULT_OSD_TIMEOUT)) 
    152                                                 color = self.get(str(i),"color", DEFAULT_OSD_COLOR) 
    153                                                 font = self.get(str(i),"font", DEFAULT_OSD_FONT) 
    154                                                 self.devices.append(OsdAlertDevice(OsdAlertDeviceInfo(position, 
    155                                                                                                                                                                 alignment, 
    156                                                                                                                                                                 offset, 
    157                                                                                                                                                                 timeout, 
    158                                                                                                                                                                 color, 
    159                                                                                                                                                                 font), 
    160                                                                                                                         alerts,areas)) 
    161                                         else: 
    162                                                 self.log.error("OSD Support Not Enabled, but OSD Device Requested!") 
    163                                 if(dev == "mythtv"): 
    164                                         to = self.getRequired(str(i),"to") 
    165                                         wait_time = int(self.getRequired(str(i),"wait_time")) 
    166                                         self.devices.append(MythtvAlertDevice(MythtvAlertDeviceInfo(to,wait_time),alerts,areas)) 
    167                                 if(dev == "media"): 
    168                                         self.devices.append(MediaAlertDevice(mediaInfo,alerts,areas)) 
    169                                 if(dev == "execution"): 
    170                                         self.devices.append(ExecutionAlertDevice(exeInfo,alerts,areas)) 
     145                                        self.devices.append(JabberAlertDevice(to,jabberInfo,alerts,areas)) 
     146                                        self.log.debug("Adding jabber device") 
     147                                else: 
     148                                        self.log.error("Jabber Support Not Enabled, but Jabber Device Requested!") 
     149                        if(dev == "osd"): 
     150                                if(not osdLoadAttempted): 
     151                                        osd_available = self.__loadOsd() 
     152                                        osdLoadAttempted = True 
     153 
     154                                if(osd_available): 
     155                                        position = self.get(str(i),"position", DEFAULT_OSD_POSITION) 
     156                                        alignment = self.get(str(i),"alignment", DEFAULT_OSD_ALIGNMENT) 
     157                                        offset = int(self.get(str(i),"offset", DEFAULT_OSD_OFFSET)) 
     158                                        timeout = int(self.get(str(i),"timeout", DEFAULT_OSD_TIMEOUT)) 
     159                                        color = self.get(str(i),"color", DEFAULT_OSD_COLOR) 
     160                                        font = self.get(str(i),"font", DEFAULT_OSD_FONT) 
     161                                        self.devices.append(OsdAlertDevice(OsdAlertDeviceInfo(position, 
     162                                                                                                                                                        alignment, 
     163                                                                                                                                                        offset, 
     164                                                                                                                                                        timeout, 
     165                                                                                                                                                        color, 
     166                                                                                                                                                        font), 
     167                                                                                                                alerts,areas)) 
     168                                        self.log.debug("Adding OSD device") 
     169                                else: 
     170                                        self.log.error("OSD Support Not Enabled, but OSD Device Requested!") 
     171                        if(dev == "mythtv"): 
     172                                to = self.getRequired(str(i),"to") 
     173                                wait_time = int(self.getRequired(str(i),"wait_time")) 
     174                                self.devices.append(MythtvAlertDevice(MythtvAlertDeviceInfo(to,wait_time),alerts,areas)) 
     175                                self.log.debug("Adding MythTv device") 
     176                        if(dev == "media"): 
     177                                self.devices.append(MediaAlertDevice(mediaInfo,alerts,areas)) 
     178                                self.log.debug("Adding media device") 
     179                        if(dev == "execution"): 
     180                                self.devices.append(ExecutionAlertDevice(exeInfo,alerts,areas)) 
     181                                self.log.debug("Adding execution device") 
    171182 
    172183        def __str__(self): 
  • StormSiren/StormWeather.py

    r122 r184  
    5656                self.__alert_devs = [] 
    5757                self.__simalert = simalert 
     58 
     59                self.log.setLevel(logging.INFO) 
    5860         
    5961        def display(self): 
  • StormSiren/TestAlert.py

    r122 r184  
    6060                self.log          = logging.getLogger("TestAlert") 
    6161 
     62                self.log.setLevel(logging.INFO) 
     63 
    6264        def fetch(self): 
    6365                self.__fetch() 
  • StormSiren/XmlWeather.py

    r122 r184  
    6464                self.log = logging.getLogger("XmlWeather") 
    6565 
     66                self.log.setLevel(logging.DEBUG) 
     67 
    6668        def fetch(self): 
    6769                self.__fetch() 
  • siren

    r135 r184  
    4343 
    4444import logging 
     45import sys 
    4546from optparse import OptionParser 
    4647 
     
    5152from StormSiren.History import History, DEFAULT_MAX_HISTORICAL_EVENTS 
    5253 
    53 __RELEASE_VERSION = "2.0 RC3" 
     54__RELEASE_VERSION = "2.0 RC4" 
    5455__RELEASE_MONTH   = "12" 
    55 __RELEASE_DAY     = "08" 
     56__RELEASE_DAY     = "01" 
    5657__RELEASE_YEAR    = "2008" 
     58 
     59logging.basicConfig(level=logging.INFO, 
     60                        format='%(asctime)s - %(name)s:%(lineno)d - %(levelname)s - %(message)s') 
    5761 
    5862def main(): 
     
    6064        log = logging.getLogger() 
    6165 
     66        log.setLevel(logging.DEBUG) 
    6267 
    6368        parser.add_option("-c", "--conf", dest="conf", 
     
    8287                                        help="Print only important messages to the console") 
    8388 
    84         parser.add_option("-l", "--logconf", dest="logconf", 
    85                                         help="Override log configuration file", metavar="file_name", default=None) 
    86  
    8789        parser.add_option("-t", "--testpage",  
    8890                                        action="store_true", dest="testpage", default=False, 
     
    9698                logging.disable(logging.info) 
    9799 
    98         conf = StormConfig(options.conf, options.logconf) 
     100        conf = StormConfig(options.conf) 
    99101 
    100102        log.info("StormSiren: v%s (%s/%s/%s)" % (__RELEASE_VERSION,  
     
    111113        #conf.display() 
    112114        #history.display() 
     115 
     116        if(len(conf.devices) == 0): 
     117                log.error("No valid devices found, exiting..") 
     118                sys.exit(1) 
    113119 
    114120        if(not options.testpage):