def setup_console_logging(level='INFO'): print('Logging to console, level=%s' % level) logging_configuration = { 'version': 1, 'formatters': { 'standard': { 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s', 'datefmt': '%Y-%m-%d %H:%M:%S' }, }, 'handlers': { 'console': { 'level': level, 'class': 'logging.StreamHandler', 'formatter': 'standard' } }, 'loggers': { '': { 'handlers': ['console'], 'level': level, 'propagate': True } } } dictConfigClass(logging_configuration).configure()
def setup_logging(filename, level='INFO', resume=False): if not resume and isfile(filename): remove(filename) print('Logging to %s, level=%s' % (filename, level)) logging_configuration = { 'version': 1, 'formatters': { 'standard': { 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s', 'datefmt': '%Y-%m-%d %H:%M:%S' }, }, 'handlers': { 'file': { 'level': level, 'class': 'logging.FileHandler', 'formatter': 'standard', 'filename': filename } }, 'loggers': { '': { 'handlers': ['file'], 'level': level, 'propagate': True } } } dictConfigClass(logging_configuration).configure()
def runworker(logbee_config, work_config): logbee_workdir = re.split(r'(/){1,}$', logbee_config.workdir)[0] + "/" logbee_logdir = re.split(r'(/){1,}$', logbee_config.logdir)[0] + "/" signal.signal(signal.SIGUSR1, end_of_job) work_name = work_config.work_name logfilename = logbee_logdir + "logbee-" + work_name + ".log" if logger.handlers: logger.handlers = [] work_logging_config = settings.get_logging_config() work_logging_config["handlers"]["file"]["filename"] = logfilename dictConfigClass(work_logging_config).configure() logger.debug("check work directory.") if not os.path.exists(logbee_workdir + work_name): logger.info("Try to create %s work directory:%s" % (work_name, logbee_workdir + work_name)) os.makedirs(logbee_workdir + work_name) else: logger.warning( "Work directory '%s' is already exist. now recreate it." % (logbee_workdir + work_name)) try: helper.delete_file(logbee_workdir + work_name) os.makedirs(logbee_workdir + work_name) except Exception as e: logger.error("recreate work directory fail.\n%s" % e) sys.exit(1) work_cache_file = logbee_workdir + work_name + "_fail_content.log" logger.info("start create cache file: %s" % work_cache_file) try: helper.make_file(work_cache_file) except Exception as e: logger.error("can't create cache file: %s" % work_cache_file) logger.error(e) sys.exit(1) logger.info("Start run logbee work: %s" % work_name) global work_job work_job = __worker(logbee_config, work_config) work_job.run_excutor()
def init_settings(): global drivers global capabilities global case_list global user_table global email_sign_table with codecs.open(__config_dir+'/logging.yaml','r',"utf-8") as config_open: logging_config = load(config_open) logging_config.setdefault("version",1) logging_config["handlers"]["file"]["filename"]=__log_dir+"\\"+logging_config["handlers"]["file"]["filename"] dictConfigClass(logging_config).configure() logger.debug("load config.yaml") with codecs.open(__config_dir + '/config.yaml','r','utf-8') as cfp: config = load(cfp) config.setdefault("version",1) capabilities = config["devices"] case_list = config["case_list"] logger.debug("load emailsigntable.csv file") csv.register_dialect('idialect',delimiter='|', quoting=csv.QUOTE_ALL) with codecs.open(__config_dir + '/emailsigntable.csv', 'r', 'utf-8') as efp: ret = csv.reader(efp,dialect='idialect') email_sign_table = Queue() for i in ret: if not i[0].startswith("#"): email_sign_table.put(i) # email_sign_table = Iqueue([i for i in ret if not i[0].startswith("#")]) logger.debug("load usertable.csv file") with codecs.open(__config_dir + '/usertable.csv', 'r', 'utf-8') as ufp: ret = csv.reader(ufp,dialect='idialect') user_table = Queue() for i in ret: if not i[0].startswith("#"): user_table.put(i) # user_table = Iqueue([i for i in ret if not i[0].startswith("#")]) logger.debug("init drivers...") drivers = [] for capabilitie in capabilities: driver = Remote("http://127.0.0.1:4723/wd/hub",desired_capabilities=capabilitie) driver.implicitly_wait(0.001) drivers.append(driver)
def configure(self): """Configure logging according to this configuration. """ dictConfigClass(self.config_dict).configure()