Skip to content

Commit 1604326

Browse files
Merge pull request #2727 from avinashkranjan/deepsource-transform-633e57a7
format code with autopep8
2 parents 4b52557 + 623d482 commit 1604326

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

WebServer/webServerlog.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
# Regular expressions for parsing the Apache Combined Log Format
55
log_pattern = r'^(\S+) (\S+) (\S+) \[([\w:/]+\s[+\-]\d{4})\] "(\S+)\s?(\S+)?\s?(\S+)?" (\d{3}) (\d+|-)'
66

7+
78
def parse_log(log_file_path):
89
with open(log_file_path, 'r') as log_file:
910
for line in log_file:
1011
match = re.match(log_pattern, line)
1112
if match:
1213
yield match.groups()
1314

15+
1416
def analyze_logs(log_file_path):
1517
# Initialize counters and sets to store information
1618
total_requests = 0
@@ -31,17 +33,19 @@ def analyze_logs(log_file_path):
3133

3234
return total_requests, len(unique_visitors), page_visits, status_codes, potential_threats
3335

36+
3437
if __name__ == "__main__":
3538
log_file_path = "path/to/your/log/file.log"
3639

37-
total_requests, unique_visitors, page_visits, status_codes, potential_threats = analyze_logs(log_file_path)
40+
total_requests, unique_visitors, page_visits, status_codes, potential_threats = analyze_logs(
41+
log_file_path)
3842

3943
print(f"Total Requests: {total_requests}")
4044
print(f"Unique Visitors: {unique_visitors}")
4145
print("\nPopular Pages:")
4246
for page, count in page_visits.most_common(10):
4347
print(f"{page}: {count} visits")
44-
48+
4549
print("\nStatus Codes:")
4650
for code, count in status_codes.items():
4751
print(f"Status Code {code}: {count} occurrences")

0 commit comments

Comments
 (0)