mirror of
				https://github.com/Thor77/TeamspeakStats.git
				synced 2025-11-03 15:22:45 -05:00 
			
		
		
		
	parse file-by-file
=> improved debugging capabilities (find corrupt log-files)
This commit is contained in:
		
							parent
							
								
									abf03d2fc7
								
							
						
					
					
						commit
						7f971acfa5
					
				
					 1 changed files with 32 additions and 32 deletions
				
			
		
							
								
								
									
										64
									
								
								tsstats.py
									
										
									
									
									
								
							
							
						
						
									
										64
									
								
								tsstats.py
									
										
									
									
									
								
							| 
						 | 
					@ -179,39 +179,39 @@ def parse_logs(log_path, ident_map={}, file_log=False):
 | 
				
			||||||
    stream_handler.setLevel(logging.INFO)
 | 
					    stream_handler.setLevel(logging.INFO)
 | 
				
			||||||
    log.addHandler(stream_handler)
 | 
					    log.addHandler(stream_handler)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # find all log-files and collect lines
 | 
					    # find all log-files and open them
 | 
				
			||||||
    log_files = [file_name for file_name in glob.glob(log_path)]
 | 
					    log_files = [open(file_name) for file_name in glob.glob(log_path)]
 | 
				
			||||||
    log_lines = []
 | 
					 | 
				
			||||||
    for log_file in log_files:
 | 
					 | 
				
			||||||
        for line in open(log_file, 'r'):
 | 
					 | 
				
			||||||
            log_lines.append(line)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # process lines
 | 
					    for log_file in log_files:
 | 
				
			||||||
    for line in log_lines:
 | 
					        # process lines
 | 
				
			||||||
        parts = line.split('|')
 | 
					        logging.debug('Started parsing of {}'.format(log_file.name))
 | 
				
			||||||
        log_format = '%Y-%m-%d %H:%M:%S.%f'
 | 
					        for line in log_file:
 | 
				
			||||||
        stripped_time = datetime.datetime.strptime(parts[0], log_format)
 | 
					            parts = line.split('|')
 | 
				
			||||||
        logdatetime = int(stripped_time.timestamp())
 | 
					            log_format = '%Y-%m-%d %H:%M:%S.%f'
 | 
				
			||||||
        data = '|'.join(parts[4:]).strip()
 | 
					            stripped_time = datetime.datetime.strptime(parts[0], log_format)
 | 
				
			||||||
        if data.startswith('client'):
 | 
					            logdatetime = int(stripped_time.timestamp())
 | 
				
			||||||
            nick, clid = re_dis_connect.findall(data)[0]
 | 
					            data = '|'.join(parts[4:]).strip()
 | 
				
			||||||
            if data.startswith('client connected'):
 | 
					            if data.startswith('client'):
 | 
				
			||||||
                client = clients[clid]
 | 
					                nick, clid = re_dis_connect.findall(data)[0]
 | 
				
			||||||
                client.nick = nick
 | 
					                if data.startswith('client connected'):
 | 
				
			||||||
                client.connect(logdatetime)
 | 
					                    client = clients[clid]
 | 
				
			||||||
            elif data.startswith('client disconnected'):
 | 
					                    client.nick = nick
 | 
				
			||||||
                client = clients[clid]
 | 
					                    client.connect(logdatetime)
 | 
				
			||||||
                client.nick = nick
 | 
					                elif data.startswith('client disconnected'):
 | 
				
			||||||
                client.disconnect(logdatetime)
 | 
					                    client = clients[clid]
 | 
				
			||||||
                if 'invokeruid' in data:
 | 
					                    client.nick = nick
 | 
				
			||||||
                    re_disconnect_data = re_disconnect_invoker.findall(data)
 | 
					                    client.disconnect(logdatetime)
 | 
				
			||||||
                    invokernick, invokeruid = re_disconnect_data[0]
 | 
					                    if 'invokeruid' in data:
 | 
				
			||||||
                    invoker = clients[invokeruid]
 | 
					                        re_disconnect_data = re_disconnect_invoker.findall(
 | 
				
			||||||
                    invoker.nick = invokernick
 | 
					                            data)
 | 
				
			||||||
                    if 'bantime' in data:
 | 
					                        invokernick, invokeruid = re_disconnect_data[0]
 | 
				
			||||||
                        invoker.ban(client)
 | 
					                        invoker = clients[invokeruid]
 | 
				
			||||||
                    else:
 | 
					                        invoker.nick = invokernick
 | 
				
			||||||
                        invoker.kick(client)
 | 
					                        if 'bantime' in data:
 | 
				
			||||||
 | 
					                            invoker.ban(client)
 | 
				
			||||||
 | 
					                        else:
 | 
				
			||||||
 | 
					                            invoker.kick(client)
 | 
				
			||||||
 | 
					        logging.debug('Finished parsing of {}'.format(log_file.name))
 | 
				
			||||||
    return clients
 | 
					    return clients
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue