Home Chapters Projects About
HomeProjects › Day 41
DAY 41 — 60 DAY PYTHON CHALLENGE

Log Analyzer

Python mein Log Analyzer banao — Hindi mein step by step

Advertisement

Project kya hai?

Day 41 ka project hai Log Analyzer! Yeh project banane se aap Python ke important concepts practice kar payenge. Neeche complete code hai — copy karo aur chalao!

Complete Python Code

python — log.py
logs = [
    "2026-03-13 10:00 INFO  Server started successfully",
    "2026-03-13 10:05 ERROR Database connection failed",
    "2026-03-13 10:06 INFO  Retrying database connection",
    "2026-03-13 10:07 ERROR Connection timeout occurred",
    "2026-03-13 10:10 WARN  Memory usage 85 percent",
    "2026-03-13 10:15 INFO  Database connection restored",
    "2026-03-13 10:20 INFO  User admin logged in",
    "2026-03-13 10:25 WARN  CPU usage high: 92 percent",
    "2026-03-13 10:30 ERROR Disk space critically low!",
    "2026-03-13 10:35 INFO  Backup completed successfully",
]

counts  = {"INFO": 0, "ERROR": 0, "WARN": 0}
errors  = []
warnings = []

for log in logs:
    parts = log.split(" ", 3)
    if len(parts) >= 3:
        level = parts[2].strip()
        if level in counts:
            counts[level] += 1
        if level == "ERROR":
            errors.append(log)
        elif level == "WARN":
            warnings.append(log)

print("=== Log Analyzer Report ===")
print(f"Total logs   : {len(logs)}")
print(f"INFO         : {counts['INFO']}")
print(f"ERROR        : {counts['ERROR']}")
print(f"WARNING      : {counts['WARN']}")

print(f"\n=== Errors ({len(errors)}) ===")
for e in errors:
    print(f"  {e}")

print(f"\n=== Warnings ({len(warnings)}) ===")
for w in warnings:
    print(f"  {w}")
OUTPUT
=== Log Analyzer Report ===
Total logs   : 10
INFO         : 5
ERROR        : 3
WARNING      : 2

=== Errors (3) ===
  2026-03-13 10:05 ERROR Database connection failed
  2026-03-13 10:07 ERROR Connection timeout occurred
  2026-03-13 10:30 ERROR Disk space critically low!

Code kaise kaam karta hai?

split(' ', 3) se log line parse hoti hai. Dictionary se level counts track hote hain. Real server log analysis isi pattern se hoti hai.
Advertisement

📋 Project ka Introduction

Log Analyzer Python ka Day 41 ka project hai. Is project mein aap Python ke important concepts practice karenge jo real-world applications mein bahut use hote hain.

Yeh project beginners ke liye design kiya gaya hai lekin kaafi concepts cover karta hai. Step by step samjho, code chalao, aur khud modify karke practice karo.

Is tarah ke projects banane se aapka Python confidence badh jaata hai aur aap asli problems solve karna seekh jaate hain. Chaliye code samjhte hain!

🧠 Is Project mein kya seekhoge?

Yeh project banate waqt aap ye Python concepts use karoge:
ConceptKya karta hai
VariablesData store karna
FunctionsReusable code blocks
LoopsRepeat karna
ConditionsDecisions lena
Input/OutputUser se interact karna

📝 Code kaise kaam karta hai — Step by Step

Neeche code ki poori logic step-by-step samjhayi gayi hai:
  1. Problem samjho: Log Analyzer mein kya karna hai
  2. Required variables aur data structures decide karo
  3. Logic step-by-step likhó
  4. Code mein implement karo
  5. Test karo aur bugs fix karo

⚠️ Common Mistakes — Bhool mat jaana!

Beginners yeh galtiyan aksar karte hain — dhyan rakho:
  • ⚠️ Indentation sahi rakho — Python mein spaces matter karti hain
  • ⚠️ Variables ko use se pehle define karo
  • ⚠️ Input ko int()/float() mein convert karo agar number chahiye
  • ⚠️ Edge cases handle karo — kya hoga agar user galat input de?

🏋️ Practice Exercises — Aage badho!

Yeh project complete karne ke baad in exercises se practice karo:
  • 💡 Log Analyzer mein naya feature add karo
  • 💡 Code ko functions mein refactor karo
  • 💡 Error handling improve karo
  • 💡 File mein data save karo

❓ Aksar Pooche Jane Wale Sawal (FAQ)

Q: Log Analyzer project kyon banana chahiye?

A: Har project ek naya concept sikhata hai. Practice se hi Python fluent aati hai.
Q: Code run nahi ho raha?

A: Indentation check karo, syntax errors dekho, variables define hain ya nahi check karo.
Q: Kaise improve karein?

A: Pehle basic version complete karo, phir ek ek feature add karte jao.