add a simple logger
This commit is contained in:
parent
08588b967f
commit
c9f0dce189
27
esgd.py
27
esgd.py
|
@ -1,9 +1,11 @@
|
|||
import socketserver
|
||||
import subprocess
|
||||
import os
|
||||
import time
|
||||
|
||||
host = "localhost"
|
||||
port = 77
|
||||
log = Logger()
|
||||
|
||||
class GopherError(BaseException): pass
|
||||
class RequestError(GopherError): pass
|
||||
|
@ -52,6 +54,31 @@ class GopherLine:
|
|||
self.port
|
||||
)
|
||||
|
||||
class Logger:
|
||||
def __init__(self, file=None):
|
||||
if file != None: self.fd = open(file, "a+")
|
||||
else: self.fd = False
|
||||
def time(self)
|
||||
return int(time.time())
|
||||
def write(self, msg):
|
||||
if self.fd: self.fd.write("{}\n")
|
||||
def log(self, msg):
|
||||
ct = self.time()
|
||||
self.write("[{}] {}".format(str(ct), msg))
|
||||
print("[{}] {}".format(str(ct), msg))
|
||||
def warn(self, msg):
|
||||
ct = self.time()
|
||||
self.write("! [{}] {}".format(str(ct), msg))
|
||||
print("! [{}] {}".format(str(ct), msg))
|
||||
def error(self, msg):
|
||||
ct = self.time()
|
||||
self.write("!! [{}] {}".format(str(ct), msg))
|
||||
print("!! [{}] {}".format(str(ct), msg))
|
||||
self.close()
|
||||
raise SystemExit
|
||||
def close(self):
|
||||
self.fd.close()
|
||||
|
||||
class GopherServerLogic:
|
||||
def recieveRequest(self):
|
||||
data = b""
|
||||
|
|
Loading…
Reference in New Issue