コード例 #1
0
ファイル: scriptmate.py プロジェクト: waymousamu/h2h
 def run(self):
     options, args = self.parser.parse_args()
     #the following so that command line options are made available
     #to the decorated function as **kwargs
     self._updatekwargs(self.parser.values.__dict__)
     logargs = (
             self.kwargs.get(OPTLOGFILE, None),
             self.kwargs.get(OPTLOGDIR, None),
             self.kwargs.get(OPTLOGPREFIX, ''),
             )
     self.kwargs[OPTLOGFILE] = logstart(*logargs)
     log.info("SCRIPT: " + sys.argv[0])
     conf = self.kwargs.get(OPTCONFIG, None)
     if conf:
         log.info("%s: %s" % (OPTCONFIG.upper(), conf.filename))
     for k,v in self.kwargs.iteritems():
         if v and k not in COMMONOPTNAMES:
             log.info("%s = %s" % (k, v))
     log.divider()
     try:
         self.func(*self.args, **self.kwargs)
     except Exception, e:
         log.exception(str(e))
         log.info("Logfile: " + self.kwargs[OPTLOGFILE])
         sys.exit(1)
コード例 #2
0
ファイル: scriptmate.py プロジェクト: waymousamu/h2h
def logstart(logfile=None, logdir=None, logprefix='itsa-'):
    '''
    Initialise file and console loggers.

    * logdir: The directory where the timestamped log file will be saved.
    * logfile: If `logdir` is not specified, log to this file.

    :return: The log file path.
    '''
    if not (logdir or logfile):
        #logdir = DEFAULTLOGDIR
        logfile = mktempfile(prefix=logprefix, suffix='.log').name
    logfile = log.start(logfile, logdir, logprefix)
    log.divider()
    if logfile:
        log.info("Started logger. Logging to file: '%s'" % logfile)
    else:
        log.info("Started logger. A log file or directory was not specified.")
    return logfile