add simple logging
This commit is contained in:
parent
c9f0dce189
commit
b3a665448a
7
esgd.py
7
esgd.py
|
@ -58,7 +58,7 @@ class Logger:
|
||||||
def __init__(self, file=None):
|
def __init__(self, file=None):
|
||||||
if file != None: self.fd = open(file, "a+")
|
if file != None: self.fd = open(file, "a+")
|
||||||
else: self.fd = False
|
else: self.fd = False
|
||||||
def time(self)
|
def time(self):
|
||||||
return int(time.time())
|
return int(time.time())
|
||||||
def write(self, msg):
|
def write(self, msg):
|
||||||
if self.fd: self.fd.write("{}\n")
|
if self.fd: self.fd.write("{}\n")
|
||||||
|
@ -163,6 +163,7 @@ class GopherServerLogic:
|
||||||
if self.fileCGI(file): fa = self.cgi(file, query)
|
if self.fileCGI(file): fa = self.cgi(file, query)
|
||||||
elif self.fileSendable(file): fa = self.fileToFileArray(file)
|
elif self.fileSendable(file): fa = self.fileToFileArray(file)
|
||||||
else:
|
else:
|
||||||
|
log.log("selector not found")
|
||||||
self.notFound()
|
self.notFound()
|
||||||
return
|
return
|
||||||
if gph: fa = self.gopherRenderer(fa)
|
if gph: fa = self.gopherRenderer(fa)
|
||||||
|
@ -170,16 +171,20 @@ class GopherServerLogic:
|
||||||
|
|
||||||
class GopherHandler(socketserver.BaseRequestHandler, GopherServerLogic):
|
class GopherHandler(socketserver.BaseRequestHandler, GopherServerLogic):
|
||||||
def handle(self):
|
def handle(self):
|
||||||
|
log.log("request from {}".format(self.client_address[0]))
|
||||||
decoded = self.recieveRequest()
|
decoded = self.recieveRequest()
|
||||||
try: parsed = self.requestParser(decoded)
|
try: parsed = self.requestParser(decoded)
|
||||||
except RequestError:
|
except RequestError:
|
||||||
|
log.log("request was invalid")
|
||||||
self.invalid()
|
self.invalid()
|
||||||
return
|
return
|
||||||
|
|
||||||
try: file = self.returnRelative(parsed[0])
|
try: file = self.returnRelative(parsed[0])
|
||||||
except RequestError:
|
except RequestError:
|
||||||
|
log.log("selector not found")
|
||||||
self.notFound()
|
self.notFound()
|
||||||
return
|
return
|
||||||
|
log.log("serving {}".format(file[0]))
|
||||||
self.serveFile(file[0], parsed[1], file[1])
|
self.serveFile(file[0], parsed[1], file[1])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue