def start_daemon(pidf, logf): # This launches the daemon in its context global debug_p if debug_p: print("nes_buttons_daemon: entered start_daemon()") print("nes_buttons_daemon: pidf={} logf={}".format(pidf, logf)) try: with daemon.DaemonContext( working_directory='/var/lib/nes_buttons', gid=grp.getgrnam('pi').gr_gid, umask=0o002, pidfile=pidfile.TimeoutPIDLockFile(pidf), ) as context: logLevel = logging.INFO logFormat = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' logger = log.initLogger(logLevel, logFormat, logf) logger.info("nes_buttons_daemon: entered daemon context") try: app = nes_buttons.NESButtons(logger) logger.info("nes_buttons_daemon: running app") app.run() except: logger.error(traceback.format_exc()) sys.exit(1) except: print("Unhandled exception: {}".format(traceback.format_exc())) sys.exit(1)
def main(): args = args_parse() cfg = config.Config(args.config) log.initLogger(args.logfile) tools.cuda_init(int(cfg['processing']['cuda_memory_limit'])) db = recdb.RecDB(cfg.get_path('files', 'db')) patt = patterns.createPatterns(cfg) patt.load() update(patt, db, int(cfg['recognition']['num_jitters']), cfg['recognition']['encoding_model'], int(cfg['processing']['max_image_size']), int(cfg['processing']['debug_out_image_size'])) rec = recognizer.createRecognizer(patt, cfg, db=db) update_db(db, rec)
def init(main): from log import initLogger from log import info from log import error initLogger() rc = 1 try: start = time.time() main() end = time.time() elapsed = end - start info("Program ran for " + str(elapsed) + " seconds.") except: rc = 0 err = traceback.format_exc() if (err != "None\n"): error(err) finally: info("Exitting")
def init(main): from log import initLogger from log import info from log import error initLogger() rc=1 try: start = time.time() main() end = time.time() elapsed= end - start info("Program ran for "+str(elapsed)+" seconds.") except: rc=0 err=traceback.format_exc() if (err!="None\n"): error(err) finally: info("Exitting")
def start_daemon( pidf, logf ): # This launches the daemon in its context global debug_p if debug_p: print( "nfc_poll_daemon: entered start_daemon()") print( "nfc_poll_daemon: pidf={} logf={}".format( pidf, logf ) ) try: with daemon.DaemonContext( working_directory='/var/lib/nfc_poll', gid = grp.getgrnam( 'pi' ).gr_gid, umask=0o002, pidfile=pidfile.TimeoutPIDLockFile( pidf ), ) as context: logLevel = logging.INFO logFormat = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' logger = log.initLogger( logLevel, logFormat, logf ) logger.info( "nfc_poll_daemon: entered daemon context" ) try: options = nfc_poll.initConfig( logger ) logger.info( "nfc_poll_daemon: options: {}".format( options ) ) app = nfc_poll.NFCPoll( options, logger ) context.signal_map = { signal.SIGTERM: app.cleanup } logger.info( "nfc_poll_daemon: running app" ) app.run() except: logger.error( traceback.format_exc() ) sys.exit(1) except: print( "Unhandled Exception: {}".format( traceback.format_exc() ) ) sys.exit(1)
#!/usr/bin/env python #coding: utf-8 import sys sys.path.append('./common') import log log.logger.setLevel(log.ERROR) if __name__ == '__main__': log.initLogger('./logs/log.txt') log.d('this is a debug message') log.i("info 1+1=%d", 1 + 1) log.w('warning: %s', 'xxxxxx') log.e('error message') log.c("critical message, exit!") log.i("xxx")
def main(): log.initLogger('./logs/analyzer.log') conv_analyzer = ConversionAnalyzer() conv_analyzer.parse_file('./20140324/conversion.log-20140324*') conv_analyzer.analyze()
else: logger.error( "Action '{}' not recognized.".format( action[ 'type' ] ) ) def run_cmd( self, cmd ): if self.process: terminate_process( self.process ) logger.debug( "Running command: {}".format( cmd ) ); self.process = subprocess.Popen( shlex.split( cmd ) ) # TODO: Do something if the user exits the process ( like using select+start in RetroArch ) def start( self ): self.read_config() self.observer.start() self.observer.join() if __name__ == "__main__": parser = argparse.ArgumentParser( description="Screen Manager" ) parser.add_argument( '-c', '--config', default='/dev/shm/screen_manager.cfg' ) parser.add_argument( '-l', '--log-file', default='/dev/shm/screen_manager.log' ) args = parser.parse_args() logger = log.initLogger( logLevel, logFormat, args.log_file ) logger.info( "Screen Manager Start" ) screenManager = ScreenManager( args.config ) screenManager.start()
from os import path import logging from utility import stdout, stderr, test_fileobj from log import LOG as log, str2loglevel, loglevel2str, toLogLevel,\ initLogger, setLogLevel from exception import AppException (pgm, ext) = path.splitext(path.basename(sys.argv[0])) # Test conversions to Python logger levels first user_levels = ('off', 'debug', 'info', 'warning', 'error', 'critical', 'nosuch') log_levels = (logging.NOTSET, logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL) stdout("initializing logging, level debug, console on, log file off.\n") initLogger(logFile=pgm, logLevel=1, logConsole=True, logDisk=False) debug = log.debug info = log.info warn = log.warn error = log.error critical = log.critical errors = 0 tests = 0 for n in range(1,6): if n == 1: debug('log.debug() called with this string') elif n == 2: info('log.info() called with this string') elif n == 3:
def main(): log.initLogger('./logs/analyzer.log') conv_analyzer = ConversionAnalyzer() conv_analyzer.parse_file('./20140324/conversion.log-20140324*') conv_analyzer.analyze()
cartridgeIds = config.options('Cartridges') cartridges = {} for uid in cartridgeIds: cartridges[uid] = config.get('Cartridges', uid) return { 'romsHome': config.get('Settings', 'roms_home'), 'screenConfig': config.get('Settings', 'screen_config_file'), 'interval': config.getint('Settings', 'interval_seconds'), 'uiPollNr': config.getint('Settings', 'ui_poll_nr'), 'uiPeriod': config.getint('Settings', 'ui_period'), 'cartridges': cartridges } if __name__ == "__main__": logLevel = logging.DEBUG logFormat = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' logger = log.initLogger(logLevel, logFormat) try: options = initConfig(logger) app = NFCPoll(options, logger) app.run() except: logger.error(traceback.format_exc()) sys.exit(1)