Repository navigation
Expand file tree
/
Copy pathfix_logging.py
More file actions
87 lines (72 loc) · 2.85 KB
/
Copy pathfix_logging.py
File metadata and controls
87 lines (72 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
"""
Fix logging statements in shutdown modules
Convert from logger.info("msg", key=value) to logger.info(f"msg: key={value}")
"""
import re
import sys
def fix_logging_in_file(filepath):
"""Fix logging statements in a file"""
with open(filepath, 'r') as f:
content = f.read()
original_content = content
# Pattern 1: logger.info("msg", key1=val1, key2=val2) -> logger.info(f"msg: key1={val1}, key2={val2}")
# Pattern 2: logger.debug("msg", key=val) -> logger.debug(f"msg: key={val}")
# Replace multi-line logging with keyword args
def replace_multiline(match):
indent = match.group(1)
level = match.group(2)
msg = match.group(3)
args = match.group(4)
# Parse keyword arguments
arg_pattern = r'(\w+)=([^,\n]+)'
arg_matches = re.findall(arg_pattern, args)
if arg_matches:
args_str = ", ".join([f"{k}={v}" for k, v in arg_matches])
return f'{indent}logger.{level}(f"{msg}: {args_str}")'
else:
return f'{indent}logger.{level}("{msg}")'
# Fix multi-line logging statements
content = re.sub(
r'(\s+)(logger\.(info|debug|warning|error))\(\s*\n?\s*"([^"]+)",\s*\n?\s*([^)]+)\)',
replace_multiline,
content
)
# Fix single-line logging with keyword args
def replace_singleline(match):
level = match.group(1)
msg = match.group(2)
args = match.group(3)
# Parse keyword arguments
arg_pattern = r'(\w+)=([^,\)]+)'
arg_matches = re.findall(arg_pattern, args)
if arg_matches:
args_str = ", ".join([f"{k}={v}" for k, v in arg_matches])
return f'logger.{level}(f"{msg}: {args_str}")'
else:
return f'logger.{level}("{msg}")'
content = re.sub(
r'logger\.(info|debug|warning|error)\("([^"]+)",\s+([^)]+)\)',
replace_singleline,
content
)
if content != original_content:
with open(filepath, 'w') as f:
f.write(content)
print(f"Fixed logging in {filepath}")
return True
else:
print(f"No changes needed in {filepath}")
return False
if __name__ == "__main__":
files = [
"/home/ubuntu/.openclaw/workspace/QA-FRAMEWORK/src/infrastructure/shutdown/connection_tracker.py",
"/home/ubuntu/.openclaw/workspace/QA-FRAMEWORK/src/infrastructure/shutdown/shutdown_manager.py",
"/home/ubuntu/.openclaw/workspace/QA-FRAMEWORK/src/infrastructure/shutdown/fastapi_integration.py",
"/home/ubuntu/.openclaw/workspace/QA-FRAMEWORK/src/infrastructure/shutdown/standalone.py",
]
for filepath in files:
try:
fix_logging_in_file(filepath)
except Exception as e:
print(f"Error fixing {filepath}: {e}")