Changeset 229


Ignore:
Timestamp:
07/20/2010 12:08:17 PM (13 years ago)
Author:
marcus
Message:

Reformatting logging module.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • SHX/trunk/src/SeismicHandler/core/log.py

    r146 r229  
    7171 
    7272            try: 
    73                 logging.basicConfig(level=logging.DEBUG, 
    74                                     format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', 
    75                                     datefmt='%Y-%m-%d %H:%M:%S', 
    76                                     filename=self.logdest, 
    77                                     filemode='w') 
     73                logging.basicConfig( 
     74                    level=logging.DEBUG, 
     75                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', 
     76                    datefmt='%Y-%m-%d %H:%M:%S', 
     77                    filename=self.logdest, 
     78                    filemode='w' 
     79                ) 
    7880            except IOError: 
    79                 self.warning("Cannot log to disc, path %s not writable! Logging everything to console." % dir) 
     81                self.warning("Cannot log to disc, path %s not writable! " 
     82                             "Logging everything to console." % dir) 
    8083 
    81                 logging.basicConfig(level=logging.DEBUG, 
    82                                     format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', 
    83                                     datefmt='%Y-%m-%d %H:%M:%S') 
    84  
     84                logging.basicConfig( 
     85                    level=logging.DEBUG, 
     86                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', 
     87                    datefmt='%Y-%m-%d %H:%M:%S' 
     88                ) 
    8589            else: 
    8690                # additional to console 
     
    9094 
    9195                # set a format which is simpler for console use 
    92                 formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') 
     96                formatter = \ 
     97                    logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') 
    9398 
    9499                # tell the handler to use this format 
     
    112117        it may not be consistent!""" 
    113118 
    114         # This method is called later by atexit, so we need to reimport the os 
    115         # module. 
    116         import os 
    117  
    118119        try: 
    119120            os.rename(self.logdest, self.backupdest) 
    120121        except Exception, e: 
    121             print e 
     122            pass 
     123#            print e 
    122124 
     125    def newLogger(self, name): 
     126        """ 
     127        Return new logger instance. It will share the basic configuration as 
     128        defined in __init__. 
     129        """ 
     130        return logging.getLogger(name) 
     131 
     132# init logging once (sets logfile, etc) 
    123133Logging() 
    124  
    125 # clean up 
    126 # logging must be kept since it's imported from other modules 
    127 del os 
Note: See TracChangeset for help on using the changeset viewer.