Mini Shell

Direktori : /usr/share/lve/dbgovernor/scripts/
Upload File :
Current File : //usr/share/lve/dbgovernor/scripts/merge_logs.py

#!/opt/cloudlinux/venv/bin/python3
# coding:utf-8

# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2024 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT
#

import re

dbgovernor_error_log	= "/var/log/dbgovernor-error.log"
dbgovernor_mysqld_log	= "/var/log/dbgovernor-mysqld.log"

def read_next_line(f):
	ln = f.readline()
	if not ln:
		return None
	m = re.match(r"\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{9})\]\s*(.*)$", ln)
	return m.groups()

def print_line(logger, ln):
	print(f"[{ln[0]}] {logger} {ln[1]}")


f1 = open(dbgovernor_error_log,  'r')
f2 = open(dbgovernor_mysqld_log, 'r')

next1 = read_next_line(f1)
next2 = read_next_line(f2)
while next1 or next2:
	if next1 and (not next2 or next1[0] <= next2[0]):
		print_line("db_gov", next1)
		next1 = read_next_line(f1)
	elif next2:
		print_line("mysqld", next2)
		next2 = read_next_line(f2)


Zerion Mini Shell 1.0