IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32084


Ignore:
Timestamp:
Aug 12, 2011, 4:01:15 PM (15 years ago)
Author:
rhenders
Message:

now handles configuration of logging, can send to stdout, or a file or both; defines a suitable name for log file and appends it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/pslogger.py

    r32037 r32084  
    11import logging.config
    2 
     2import datetime
     3import os
     4import sys
    35
    46class PSLogger(logging.getLoggerClass()):
     7
     8   '''
     9   Sets up logging using values from the ippToPsps config file
     10   '''
     11   def setup(self, doc, name, stdout=1, sendToFile=0):
     12
     13       formatter = logging.Formatter('%(asctime)s | %(levelname)7s | %(message)s', '%Y-%m-%d %H:%M:%S')
     14       self.setLevel(logging.INFO)
     15
     16       if sendToFile:
     17           PATH = doc.find("localOutPath").text + "/log"
     18           if not os.path.exists(PATH): os.makedirs(PATH)
     19           DVOLABEL = doc.find("dvo/gpc1Label").text
     20           FULLPATH = PATH + "/" + name + "_" + DVOLABEL + ".log"
     21
     22           # opens file to be appended
     23           hdlr = logging.FileHandler(FULLPATH, "a")
     24           hdlr.setFormatter(formatter)
     25           self.addHandler(hdlr)
     26
     27       if stdout:
     28           stdout = logging.StreamHandler(sys.__stdout__)
     29           stdout.setFormatter(formatter)
     30           self.addHandler(stdout)
     31
     32       if sendToFile: print "Writing log to: " + FULLPATH
    533
    634   def infoPair(self, first, second):
     
    1442
    1543   def infoTitle(self, str):
     44       self.info("")
    1645       self.info("%40s" % (str))
    1746       self.info("")
Note: See TracChangeset for help on using the changeset viewer.