def dump_logs(app_name): d = read_json_config(APP_CONFIG) for i in d: if i.get('app_name') == app_name: config = Config(**i) parser = ParserFactory.get_instance_for_app(config) for _ in range(15): parser.dump_logs(100, test_log_lines=test_log_lines) print("Dumped logs!") time.sleep(10)
def _parse_config(): # Read config file and fetch list of apps config_list = read_json_config(constants.APP_CONFIG) # Create instances for config in config_list: # Skip those apps which where already processed if config['app_name'] in PollManager.POLL_JOB_DB: continue config_obj = Config(**config) print(f'Detected new app for polling: {config_obj.app_name}') PollManager.POLL_JOB_DB[config_obj.app_name] = { 'app_log': AppLog(config_obj), 'status': constants.SCHEDULED }
print(f'Failed to store log info into ES: {e}') def start_poll(self): polling_interval = self.config.poll_interval print( f'Started polling against log for app: {self.config.app_name} for ' f'every "{polling_interval}" seconds') while True: self.poll_logs() time.sleep(polling_interval) def __repr__(self): return f'Applog<{self.config.app_name}>' if __name__ == '__main__': from constants import APP_CONFIG from log_parser.file_util import read_json_config, pretty_print # Read json config as dictionary # config_json = read_json_config(APP_CONFIG)[0] config_json = read_json_config(APP_CONFIG)[1] # Create configuration object _config = Config(**config_json) # Create AppLog object app_log = AppLog(_config) app_log.start_poll()
from dataclasses import dataclass import os from constants import LOG_DIR @dataclass class Config: app_name: str message_format: str log_file: str poll_interval: int def __post_init__(self): self.app_log = os.path.join(LOG_DIR, self.app_name, self.log_file) if __name__ == '__main__': from constants import APP_CONFIG from log_parser.file_util import read_json_config, pretty_print config_data = read_json_config(APP_CONFIG)[0] config = Config(**config_data) print(config)
def test_poll_log(): d = read_json_config(APP_CONFIG) for i in d: pretty_print(i) config = Config(**i) parser = ParserFactory.get_instance_for_app(config)