if request.url_rule.endpoint.startswith('api_'): response = jsonify({'message': error.message}) else: response = render_template('_404.html') logger.debug(error.message) return response, 404 @babel.localeselector def get_locale(): """Return the best matched language supported.""" return request.accept_languages.best_match(LANGUAGES.keys()) if __name__ == "__main__": # load config config.load_file("configs/development.yaml") # log setup handlers = loghelper.setup_logging(config['log_directory'], verbose=True) for h in handlers: app.logger.addHandler(h) h.setLevel(logging.DEBUG) app.logger.setLevel(logging.DEBUG) # set up the backend engine = create_engine(config["db_engine"], echo=True) kilinkbackend = backend.KilinkBackend(engine) app.run(debug=True, host='0.0.0.0')
import logging import loghelper import gitexec loghelper.setup_logging() logger = logging.getLogger(__name__) gitexec.gitExec(gitexec.loadConfig("souphelper"), "status")
def main(): # read settings, must be valid json settings = read_settings() # set up logging setup_logging( settings['log_path'], file_level=logging.DEBUG, console_level=logging.INFO, logrotate_filesize=settings['logrotate_filesize'], logrotate_numfiles=settings['logrotate_numfiles'], # file_formatter='%(asctime)s - %(name)s - %(levelname)s - %(message)s', # console_formatter='%(asctime)8s %(levelname)5s - %(message)s' ) logger.info(70*"*") logger.info("*** SWM GUI ".ljust(70, '*')) logger.info(70*"*") logger.info("") logger.info("log_path: %s" % settings['log_path']) logger.info("logrotate_filesize: %s" % settings['logrotate_filesize']) logger.info("logrotate_numfiles: %s" % settings['logrotate_numfiles']) parser = argparse.ArgumentParser(description='Smart Wheel GUI.') parser.add_argument('config_filenames', metavar='config_filenames', type=str, nargs='*', help='config filenames, run "python3 config.py" if you do not have any.') args = parser.parse_args() logger.info("command line arguments: %s" % str(args)) root = tk.Tk() root.title("Opteq Smart Wheel controller") smart_modules = [] smart_wheels_loaded = False has_argument_files = False load_state_failed = False config_filenames = args.config_filenames if config_filenames: logger.info("Starting from config filenames [%s]..." % ', '.join(config_filenames)) has_argument_files = True if os.path.exists(GUI_STATE_FILENAME) and not has_argument_files: logger.info("Starting from state file [%s]..." % GUI_STATE_FILENAME) try: smart_modules = smart_wheels_from_state_file(GUI_STATE_FILENAME) smart_wheels_loaded = True except: logger.exception("Load from [%s] failed." % GUI_STATE_FILENAME) if not smart_wheels_loaded: if not config_filenames: # if they didn't come from cmdline config_filenames = ['default_propeller.json', 'default_mock.json', 'default_ethernet.json', ] logger.info("Starting with default settings [%s]..." % ', '.join(config_filenames)) for filename in config_filenames: logger.info('Reading config file [%s]...' % filename) conn = connection.Connection.from_file(filename) new_sm = SWMGuiElements(connection=conn, populate_incoming=POPULATE_INCOMING) smart_modules.append(new_sm) # If anything is wrong, it should have crashed # log files for sm in smart_modules: filename = os.path.join( settings['log_path'], '%s.log' % sm.extra['wheel_slug']) logger.info("Look for logfile at [%s]" % filename) # os.remove(filename) # if os.path.exists(filename): # logger.info("Delete existing logfile at [%s]" % filename) # os.remove(filename) interface = Interface(root, smart_modules) root.protocol("WM_DELETE_WINDOW", interface.quit) # close window root.mainloop()