Skip to content

Commit

Permalink
Server: Write server logs to server_logs folder with unique filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
goldarte committed Nov 9, 2019
1 parent de903d2 commit 68dbf57
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import socket
import random
import logging
import datetime
import threading
import selectors
import collections
Expand All @@ -17,11 +18,22 @@

random.seed()

now = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")

path = 'server_logs'
if not os.path.exists(path):
try:
os.mkdir(path)
except OSError:
print("Creation of the directory %s failed" % path)
else:
print("Successfully created the directory %s " % path)

logging.basicConfig( # TODO all prints as logs
level=logging.DEBUG,
format="%(asctime)s [%(name)-7.7s] [%(threadName)-19.19s] [%(levelname)-7.7s] %(message)s",
handlers=[
logging.FileHandler("server_logs.log"),
logging.FileHandler("server_logs/{}.log".format(now)),
logging.StreamHandler()
])

Expand Down

0 comments on commit 68dbf57

Please sign in to comment.