Commit 5269f460 authored by Ralf's avatar Ralf

time in log

parent 9cc99edf
......@@ -60,15 +60,15 @@ class Game:
def logDebug(self, *args):
if self.logFile is not None:
log_file(self.logFile, *args)
log_file(self.logFile, *args, clock=True)
def logInfo(self, *args):
log_file(sys.stdout, *args)
if self.logFile is not None:
log_file(self.logFile, *args)
log_file(self.logFile, *args, clock=True)
def logError(self, *args):
log_file(sys.stderr, *args)
if self.logFile is not None:
log_file(self.logFile, *args)
log_file(self.logFile, *args, clock=True)
def showAdmins(self):
if not self.admins: return
......
import threading, traceback, sys
from datetime import datetime
# run a Python command asynchronously
def fire_and_forget(f):
......@@ -11,7 +12,13 @@ def fire_and_forget(f):
t.start()
def send_async(conn, data):
fire_and_forget(lambda: conn.send(data))
def do_send():
try:
conn.send(data)
except OSError:
pass
fire_and_forget(do_send)
def log_file(file, *args):
print(*args, file=file, flush=True)
\ No newline at end of file
def log_file(file, *args, clock=False):
prefix = datetime.now().strftime("%Y-%m-%d %H:%M:%S: ") if clock else ""
print(prefix, *args, file=file, flush=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment