Write log files to directory

Move index file to parent directory, remove template directory
This commit is contained in:
Иван Солнцев 2024-06-04 17:25:11 +03:00
parent f7d2a675fb
commit 7697b7463e
6 changed files with 30 additions and 19 deletions

View file

@ -1,9 +1,7 @@
from logging import NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL from logging import NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL
import testmod
from server.urlhandler import path from server.urlhandler import path
import testmod
SETUP = { SETUP = {
"setup": { "setup": {

View file

@ -1,7 +1,13 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os
from server.main import start from server.main import start
if __name__ == "__main__": if __name__ == "__main__":
try:
os.mkdir(os.path.join(os.getcwd(), "log"))
except OSError:
pass #print("dir is exists")
start() start()

View file

@ -1,6 +1,7 @@
import threading import threading
import socket import socket
import logging import logging
import os
import config import config
@ -188,8 +189,13 @@ class HTTPHandler:
def start(): def start():
logging.basicConfig(filename="main.log", filemode="a", encoding="UTF-8", logging.basicConfig(
level=config.SETUP["setup"]["log_level"], format="[%(asctime)s][%(levelname)s] %(message)s") filename=os.path.join(os.getcwd(), "log", "main.log"),
filemode="a",
encoding="UTF-8",
level=config.SETUP["setup"]["log_level"],
format="[%(asctime)s][%(levelname)s] %(message)s"
)
project_logotype = """ project_logotype = """
___________ _____ _____________ ___________ _____ _____________

View file

@ -1,7 +1,18 @@
import os
def path(path="/", _type="static-file", link="index.html", methods=("GET",)): def path(path="/", _type="static-file", link="index.html", methods=("GET",)):
if _type == "static-file": if _type == "static-file":
return {path: (methods, _type, "static/{}".format(link))} return {
if _type == "redirect": path: (methods, _type, os.path.join(os.getcwd(), link))
return {path: (methods, _type, link)} }
elif _type == "redirect":
return {
path: (methods, _type, link)
}
elif _type == "function": elif _type == "function":
return {path: (methods, _type, link)} return {
path: (methods, _type, link)
}

View file

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>CatNet Template</title>
</head>
<body>
<h1>Template has been loaded</h1>
<p>{template_data}</p>
</body>
</html>