def main(): level = ArgumentParser().start() if level is not None: LogHandler(log_level=level) else: LogHandler() process_data = ProcessData() #process_data.test_jitbit() process_data.start()
def start_logging (self): if self._logger is not None: return self._logger = logging.getLogger('Logger1') self._logger.setLevel(logging.DEBUG) log_full_path_file_name = '%s/log.log' % os.path.dirname(os.path.realpath(__file__)) log_file_info = QFileInfo(log_full_path_file_name) if log_file_info.exists(): log_created_qdatetime = log_file_info.created() current_qdatetime = QDateTime.currentDateTime() max_difference_secs = 60 * 60 * 24 * 7 # 7 giorni current_difference_secs = log_created_qdatetime.secsTo(current_qdatetime) if current_difference_secs > max_difference_secs: QFile.remove(log_full_path_file_name) self._log_handler = LogHandler(log_full_path_file_name) formatter = logging.Formatter('%(asctime)s - %(thread)d - %(name)s - %(levelname)s - %(message)s') self._log_handler.setFormatter(formatter) self._logger.addHandler(self._log_handler) # Do not raise logging system exceptions logging.raiseExceptions = False # Connect log signal self._log_handler.logged.connect (self.message_logged) self.logging_enabled = True
def main(): LogHandler.merge_session() LogHandler.backup() handler = LogHandler() try: while True: handler.update_session() LogHandler.sleep() except: handler.update_session() LogHandler.merge_session() handler.print_progress_today(force=True)
def setUp(self): """Initialization of the tests""" # Create temporary log file for testing the methods self.logPath = "tmp.log" self.generatingRate = 60 self.entryGenerator = EntryGenerator(self.logPath, self.generatingRate) now = datetime.now() # Add a 10 hours old entry self.entryGenerator.write_entry(now - timedelta(hours=10)) # Add two entries to the current time self.entryGenerator.write_entry(now) self.entryGenerator.write_entry(now) # Setup the LogHandler object prior testing self.refreshPeriod = 2 self.alertThreshold = 20 self.monitorDuration = 10 self.logHandler = LogHandler(self.logPath, self.refreshPeriod, self.alertThreshold, self.monitorDuration) # Disable logHandler console output for the tests self.logHandler.printStatus = False
def main(args): try: logging.basicConfig(level=args.log_level) except ValueError as e: print('Unable to initialise logging: %s' % e) raise SystemExit logging.info('Starting the server...') logging.info('Version: %s.', server_version()) config.config = config.Config.load(args.config_file) from db import load_db, dump_db load_db() from networking import factory listener = reactor.listenTCP(config.config.port, factory, interface=config.config.interface) logging.info('Listening on %s:%d.', listener.interface, listener.port) from log_handler import LogHandler logging.getLogger().addHandler(LogHandler()) reactor.run() logging.info('Server shutting down.') dump_db() config.config.dump(args.config_file)
# Run the HTTP monitor with parameters from parameters.cfg from log_handler import LogHandler import configparser config = configparser.ConfigParser() config.read("parameters.cfg") logPath = str(config.get("Monitor", "logPath")) refreshPeriod = float(config.get("Monitor", "refreshPeriod")) treshold = float(config.get("Monitor", "treshold")) monitorDuration = float(config.get("Monitor", "monitorDuration")) logHandler = LogHandler(logPath, refreshPeriod, treshold, monitorDuration) logHandler.start() # Wait for the logHandler to finish to end the program logHandler.join()
def game(): # load logs and lithology log_info = LogHandler() # game parameters and initial settings clock = pg.time.Clock() done = False selected_user_lith = "Unknown" # start drawing # Fill the background with DARK GREY screen.fill(art.DARK_GREY) # draw chart background pg.draw.rect(screen, art.GREY, [20, 20, 685, 710], 0) # draw log chart # background pg.draw.rect(screen, art.WHITE, [40, 40, 645, 670], 0) well_names = [ 'BLUE MAVERICK 34-1', 'BIG CRAWDAD 25-3-34', 'BIG MONEY HONEY 6-43-5H', 'BEANS STATION 15-8-1H', 'AUNT MABEL 25-9-23', 'LIONS GRASP 4-32-50', 'BOBS COUCH 10-5-23 4', 'PETERSON RANCH 4-25-3 1H', 'BLACK GOLD 2-45', 'FINGERS CROSSED 9-12', ] # draw well name and info header_text = header_font.render(well_names[random.randint(0, 9)], True, art.BLACK) screen.blit(header_text, (int(370 - (.5 * header_text.get_rect().width)), 60)) # log labels and scale gr_text = font.render('0 —— Gamma Ray (API) —— 150', True, art.BLACK) pe_text = font.render('0 ———— Pe (barns/e) ———— 10', True, art.RED) dp_text = font.render( '30 ————-——— Density Porosity (ls eq. units) ———————— -10', True, art.GREEN) np_text = font.render( '30 ————-——— Neutron Porosity (ls eq. units) ———————— -10', True, art.BLACK) # track 1 (Gamma Ray) # track1_surface_size = (180, 500) track1_surface_location = (60, 190) # draw log label and scale screen.blit( gr_text, (track1_surface_location[0] - 3, track1_surface_location[1] - 25)) # draw the track surface draw_track(screen, log_info, track1_surface_size, track1_surface_location, 1) # track 2 (Depth) # track2_surface_size = (65, 500) track2_surface_location = (240, 190) track2 = pg.Surface(track2_surface_size) track2.fill(art.WHITE) # draw depth values and markers draw_depth(track2, log_info.n_zones, log_info.logs['DEPTH']) screen.blit(track2, track2_surface_location) # track 3 (PE, Density, Neutron) # track3_surface_size = (360, 500) track3_surface_location = (305, 190) # draw log label and scale screen.blit( pe_text, (track3_surface_location[0] - 3, track3_surface_location[1] - 75)) screen.blit( dp_text, (track3_surface_location[0] - 3, track3_surface_location[1] - 50)) screen.blit( np_text, (track3_surface_location[0] - 3, track3_surface_location[1] - 25)) # draw the track surface draw_track(screen, log_info, track3_surface_size, track3_surface_location, 3) # create buttons # depth track lith buttons lith_buttons = [] for x in range(0, log_info.n_zones): height = track2_surface_size[1] / log_info.n_zones lith_buttons.append( LithButton(track2_surface_location, 0, int(x * height), track2_surface_size[0], height)) # button screen buttons_surface = pg.Surface((300, 710)) buttons_surface_location = (725, 20) buttons_surface.fill(art.GREY) # create user lith buttons halite_button = Button(buttons_surface_location, 20, 105, 80, 50, 'Halite') gypsum_button = Button(buttons_surface_location, 110, 105, 80, 50, 'Gypsum') anhydrite_button = Button(buttons_surface_location, 200, 105, 80, 50, 'Anhydrite') dolomite_button = Button(buttons_surface_location, 110, 165, 80, 50, 'Dolomite') dolomitcls_button = Button(buttons_surface_location, 20, 225, 80, 50, 'Dolomitic LS') chertydolls_button = Button(buttons_surface_location, 110, 225, 80, 50, 'Cherty Dol LS') chertydol_button = Button(buttons_surface_location, 200, 225, 80, 50, 'Cherty Dol') limestone_button = Button(buttons_surface_location, 20, 285, 80, 50, 'Limestone') chertyls_button = Button(buttons_surface_location, 110, 285, 80, 50, 'Cherty LS') chert_button = Button(buttons_surface_location, 200, 285, 80, 50, 'Chert') shale_button = Button(buttons_surface_location, 110, 345, 80, 50, 'Shale') sandstone_button = Button(buttons_surface_location, 20, 405, 80, 50, 'Sandstone') ironstone_button = Button(buttons_surface_location, 110, 405, 80, 50, 'Ironstone') coal_button = Button(buttons_surface_location, 200, 405, 80, 50, 'Coal') newlognolith_button = Button(buttons_surface_location, 75, 485, 150, 30, 'New log without lithology') newloglith_button = Button(buttons_surface_location, 75, 525, 150, 30, 'New log with lithology') checklith_button = OnOffButton(buttons_surface_location, 75, 565, 150, 30, 'Check lithology', False) pg.display.update() while not done: # draw user lith buttons halite_button.draw(buttons_surface, selected_user_lith) gypsum_button.draw(buttons_surface, selected_user_lith) anhydrite_button.draw(buttons_surface, selected_user_lith) dolomite_button.draw(buttons_surface, selected_user_lith) dolomitcls_button.draw(buttons_surface, selected_user_lith) chertydolls_button.draw(buttons_surface, selected_user_lith) chertydol_button.draw(buttons_surface, selected_user_lith) limestone_button.draw(buttons_surface, selected_user_lith) chertyls_button.draw(buttons_surface, selected_user_lith) chert_button.draw(buttons_surface, selected_user_lith) shale_button.draw(buttons_surface, selected_user_lith) sandstone_button.draw(buttons_surface, selected_user_lith) ironstone_button.draw(buttons_surface, selected_user_lith) coal_button.draw(buttons_surface, selected_user_lith) newlognolith_button.draw(buttons_surface) newloglith_button.draw(buttons_surface) checklith_button.draw(buttons_surface) # check for button clicks for event in pg.event.get(): if event.type == pg.QUIT: done = True if event.type == pg.MOUSEBUTTONDOWN: if halite_button.selected(event.pos): selected_user_lith = 'Halite' break if gypsum_button.selected(event.pos): selected_user_lith = "Gypsum" break if anhydrite_button.selected(event.pos): selected_user_lith = "Anhydrite" break if dolomite_button.selected(event.pos): selected_user_lith = "Dolomite" break if dolomitcls_button.selected(event.pos): selected_user_lith = "Dolomitic LS" break if chertydolls_button.selected(event.pos): selected_user_lith = "Cherty Dol LS" break if chertydol_button.selected(event.pos): selected_user_lith = "Cherty Dol" break if limestone_button.selected(event.pos): selected_user_lith = "Limestone" break if chertyls_button.selected(event.pos): selected_user_lith = "Cherty LS" break if chert_button.selected(event.pos): selected_user_lith = "Chert" break if shale_button.selected(event.pos): selected_user_lith = "Shale" break if sandstone_button.selected(event.pos): selected_user_lith = "Sandstone" break if ironstone_button.selected(event.pos): selected_user_lith = "Ironstone" break if coal_button.selected(event.pos): selected_user_lith = "Coal" break if newlognolith_button.selected(event.pos): log_info = LogHandler() draw_track(screen, log_info, track1_surface_size, track1_surface_location, 1) draw_track(screen, log_info, track3_surface_size, track3_surface_location, 3) track2.fill(art.WHITE) draw_depth(track2, log_info.n_zones, log_info.logs['DEPTH']) for button in lith_buttons: button.lith_status = 'Unknown' break if newloglith_button.selected(event.pos): log_info = LogHandler() draw_track(screen, log_info, track1_surface_size, track1_surface_location, 1) draw_track(screen, log_info, track3_surface_size, track3_surface_location, 3) for i, button in enumerate(lith_buttons): button.lith_status = log_info.get_lith( log_info.true_lith[i]) track2.blit(log_info.get_lith_art(button.lith_status), (button.x, button.y)) draw_depth(track2, log_info.n_zones, log_info.logs['DEPTH']) break checklith_button.selected(event.pos) # draw lith buttons for button in lith_buttons: if button.selected(event.pos, selected_user_lith): for button_2 in lith_buttons: track2.blit( log_info.get_lith_art(button_2.lith_status), (button_2.x, button_2.y)) draw_depth(track2, log_info.n_zones, log_info.logs['DEPTH']) break if checklith_button.status: text = font.render('x', True, art.RED) for i, button in enumerate(lith_buttons): if button.lith_status != 'Unknown': if log_info.get_lith(button.lith_status) != int( log_info.true_lith[i]): track2.blit(text, (button.x + 3, button.y - 2)) screen.blit(track2, track2_surface_location) screen.blit(buttons_surface, buttons_surface_location) pg.display.update() clock.tick(30)
logger.error("Invalid date/time format: {0}.".format(dt)) sys.exit(1) return '%d-%02d-%02d %02d:%02d:%02d' % (year, month, day, hour, min, sec) #------------------------------------------------------------------------------ """ Main """ #------------------------------------------------------------------------------ if __name__ == "__main__": # subscribe for signal from version import __version__ logger = LogHandler('hcdiag_query', logging.DEBUG) #logger.open_console(logging.DEBUG) # now we can start logging! logger.info('{0}, version {1}, running on {2} {3}, {4} machine.' \ .format( __file__, __version__, os.uname()[0], os.uname()[2], os.uname()[1].split(".")[0])) parser = argparse.ArgumentParser() parser.add_argument( '--runid', '-r', type=str, nargs='+', metavar='id', help= 'unique udentifier of the diagnostic run. All other arguments will be ignored.'
from resources.user_agent import USER_AGENT_FIREFOX from lxml import etree from mongo.mongo import db from redisclient.redis_pool import redis_client from log_handler import LogHandler import time import os import urllib import asyncio import aiohttp from compress_util import Compress as compress log = LogHandler("baidubaike") class BaiduBaike: def __init__(self): # 百科首页 self.baike_home = "http://baike.baidu.com" # 请求头 self.header = { "user-agent": USER_AGENT_FIREFOX, "host": "baike.baidu.com", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "accept-language": "zh-CN,en-US;q=0.8,zh;q=0.7,zh-TW;q=0.5,zh-HK;q=0.3,en;q=0.2", "accept-encoding": "gzip, deflate, br", "connection": "keep-alive", "upgrade-insecure_requests": "1", "cache-control": 'max-age=0',
def _init_loghandler(log_path): return LogHandler(log_path)
print 'Can not find csmi directory {0}. Is csmi installed?'.format( csmidir) sys.exit(1) usecsm = True runid = datetime.now().strftime("%y%m%d%H%M%S%f") logd = '%s/%s' % (mconfig['logdir'], runid) logf = '%s/%s-%s.log' % (mconfig['logdir'], me, runid) console_level = VERBOSE_LEVEL[mconfig['console_verbose'].lower()] log_level = VERBOSE_LEVEL[mconfig['log_verbose'].lower()] bds = True if mconfig['bds'].lower() == 'yes' else False try: logger = LogHandler(thismodule, console_level, log_level, True, bds, logf) except IOError as e: print e print 'Error creating the log handlers. Exiting...' sys.exit(1) thisuser = getpass.getuser() csmii = csmi.CsmiInterface(logger, csmidir, usecsm, mconfig['allocation_id'], runid, thisuser) logger.set_csmi(csmii) if mgmt_mode: import harness tharness = harness.Harness(mconfig, tconfig, logger, runid, logd, csmii, thisuser, args.target) else:
def __init__(self): log = LogHandler('refresh_schedule') ProxyManager.__init__(self, log)
import tkinter import multiprocessing from log_handler import LogHandler LogHandler.merge_session() LogHandler.backup() handler = LogHandler() def close(): thread_update.terminate() handler.update_session() LogHandler.merge_session() handler.print_progress_today(force=True) base_window.destroy() def func_update(): while True: handler.update_session() handler.print_progress_today(force=False) LogHandler.sleep() if __name__ == '__main__': base_window = tkinter.Tk() base_window.title('clock-in') thread_update = multiprocessing.Process(target=func_update) thread_update.start()
def __init__(self): log = LogHandler('valid_schedule') ProxyManager.__init__(self, log) Thread.__init__(self)
from log_handler import LogHandler from ssh_handler import SSHHandler from celery import Celery app = Flask(__name__, instance_relative_config=True) app.config.from_object('config') app.config.from_pyfile('settings.py', silent=True) db = SQLAlchemy(app) Bootstrap(app) try: datahandler = DataHandler(app.config['DATALOCATION'], netboxURL=app.config['NETBOXSERVER']) except KeyError: datahandler = DataHandler('local') logger = LogHandler(app.config['SYSLOGFILE']) sshhandler = SSHHandler() # Celery celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'], backend=app.config['CELERY_RESULT_BACKEND']) celery.conf.update(app.config) from app import views, models manager = Manager(app) if __name__ == "__main__": app.secret_key = os.urandom(25) manager.run()
# -*- coding: utf-8 -*- import time from car_parts.abstract_car_part_handler import AbstractCarPartHandler from log_handler import LogHandler logger = LogHandler().get_logger(__name__) class Lambda(AbstractCarPartHandler): """ Wraps a function into a vehicle part. """ def __init__(self, f): """ Accepts the function to use. """ self.f = f def start(self, *args, **kwargs): return def update(self, *args, **kwargs): return def run_threaded(self, *args, **kwargs): return def run(self, *args, **kwargs): return self.f(*args, **kwargs)
""" Copyright(c) 2018 Gang Zhang All rights reserved. Author:Gang Zhang Date:2018.02.01 """ from flask import Flask, jsonify, request from log_handler import LogHandler from proxy_manager import ProxyManager app = Flask(__name__) logger = LogHandler('proxy_api') api_list = { 'get': u'get an usable proxy', 'get_all': u'get all proxy from proxy pool', 'delete?proxy=127.0.0.1:8080': u'delete an unable proxy', 'get_status': u'proxy statistics' } @app.route('/') def index(): return jsonify(api_list) @app.route('/get/') def get(): proxy = ProxyManager(logger).get()
COUNTRIES, SCORE_THRESHOLD, RUMOR_THRESHOLD, USEFUL_THRESHOLD, SENTIMENT_THRESHOLD, ITOPICS, ECOUNTRY_ICOUNTRIES_MAP, ) logger = logging.getLogger(__file__) cfg = load_config() meta_data_handler = MetaDataHandler() db_handler = DBHandler(**cfg["db_handler"]) log_handler = LogHandler(**cfg["log_handler"]) twitter_handler = TwitterHandler(**cfg["twitter_handler"]) def update_database(do_tweet: bool = False): logger.debug("Add automatically categorized pages.") data_path = cfg["data"]["article_list"] cache_file = f'{cfg["log_handler"]["log_dir"]}/offset.txt' if os.path.exists(cache_file): with open(cache_file) as f: offset = int(f.read().strip()) else: offset = 0 logger.debug(f"Skip the first {offset} lines.") maybe_tweeted_ds = [] with open(data_path, mode="r", encoding="utf-8", errors="ignore") as f:
if os.name == 'nt': os.system('cls') else: os.system('clear') def menuloop(csv_file): while True: clear() print("Work Log Terminal: Main Menu\n") print("1. Add new entry") print("2. View and/or edit Data") print("3. Clear/Reset Work Log Data") print("4. Quit\n") print("Please enter the number of the option you wish to choose.") choice = input("> ") if choice == '1': csv_file.write_to_log() elif choice == '2': print(csv_file.search_log()) elif choice == '3': csv_file.reset_log() elif choice == '4': clear() break else: print("Invalid Input") input("Press Enter") csv_file = LogHandler('log.csv') menuloop(csv_file)