-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
36 lines (29 loc) · 1.13 KB
/
server.py
File metadata and controls
36 lines (29 loc) · 1.13 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
from http.server import SimpleHTTPRequestHandler, HTTPServer
import logging
from colorama import init, Fore, Style
# Initialize colorama
init(autoreset=True)
PORT = 8000
# Custom Logging Handler
class LoggingHandler(SimpleHTTPRequestHandler):
def log_message(self, format, *args):
client_ip = self.client_address[0]
time = self.log_date_time_string()
msg = format % args
log_line = f"{Fore.CYAN}{Style.RESET_ALL} - " \
f"[{Fore.YELLOW}{time}{Style.RESET_ALL}] " \
f"{Fore.GREEN}{msg}{Style.RESET_ALL}"
logging.info(log_line)
if __name__ == "__main__":
logging.basicConfig(
level=logging.INFO,
format="%(message)s", # শুধু কাস্টম মেসেজ দেখাবে
handlers=[logging.StreamHandler()]
)
server = HTTPServer(("0.0.0.0", PORT), LoggingHandler)
print(f"{Fore.MAGENTA}Serving at http://127.0.0.1:{PORT}{Style.RESET_ALL}")
try:
server.serve_forever()
except KeyboardInterrupt:
print(f"\n{Fore.RED}Shutting down server...{Style.RESET_ALL}")
server.server_close()