Esempio n. 1
0
 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)
Esempio n. 2
0
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
Esempio n. 3
0
 def inner(config, logfile, *args):
     if isinstance(config, str):
         conf_file = config
         config = ConfigParser()
         config.readfp(open(conf_file))
     logger.start(logfile=logfile)
     sourcefile = inspect.getabsfile(main)
     logger.info('*** Starting logger ***')
     logger.info('*** Running file %s ***' % sourcefile)
     try:
         main(config, logfile, *args)
     except:
         logger.exception("Unexpected Error.")
     logger.info('*** Leaving file %s ***' % sourcefile)
     logger.info('*** Stopping logger ***')
     logger.end()
Esempio n. 4
0
def _log_info(msg):
    log.info("%s - %s" % (hostname, msg))