From: ThomasV Date: Sun, 1 Apr 2012 17:10:58 +0000 (+0400) Subject: improved logging X-Git-Url: https://git.novaco.in/?p=electrum-server.git;a=commitdiff_plain;h=549ff3f84b6ea240285659e29ed613aa9a2182d7 improved logging --- diff --git a/modules/irc/__init__.py b/modules/irc/__init__.py index 59f0db6..4d3c448 100644 --- a/modules/irc/__init__.py +++ b/modules/irc/__init__.py @@ -100,7 +100,7 @@ class ServerProcessor(Processor): result = self.get_peers() elif method == 'server.version': - print "version", params + pass elif method == 'server.stop': print "stopping..." diff --git a/processor.py b/processor.py index c6da150..84af962 100644 --- a/processor.py +++ b/processor.py @@ -5,6 +5,14 @@ import time import traceback, sys import Queue as queue +def random_string(N): + import random, string + return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N)) + +def timestr(): + return time.strftime("[%d/%m/%Y-%H:%M:%S]") + + class Shared: def __init__(self): @@ -125,6 +133,9 @@ class RequestDispatcher(threading.Thread): except: traceback.print_exc(file=sys.stdout) + if method in ['server.version']: + session.version = params[0] + def add_session(self, session): with self.lock: @@ -149,6 +160,19 @@ class Session: self._stopped = False self.lock = threading.Lock() self.subscriptions = [] + self.address = '' + self.name = '' + threading.Timer(2, self.info).start() + + def info(self): + for s in self.subscriptions: + m, p = s + if m == 'blockchain.address.subscribe': + addr = p[0] + break + else: + addr = None + print timestr(), self.name, self.address, addr, len(self.subscriptions), self.version def stopped(self): with self.lock: diff --git a/transports/native.py b/transports/native.py index 2ed7ff9..2cc4313 100644 --- a/transports/native.py +++ b/transports/native.py @@ -1,13 +1,8 @@ import thread, threading, time, socket, traceback, ast, sys +from processor import timestr, random_string -def random_string(N): - import random, string - return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N)) - -def timestr(): - return time.strftime("[%d/%m/%Y-%H:%M:%S]") def new_to_old(s): diff --git a/transports/stratum_http.py b/transports/stratum_http.py index 25e0738..47ef744 100644 --- a/transports/stratum_http.py +++ b/transports/stratum_http.py @@ -47,11 +47,7 @@ from the processor point of view: """ -def random_string(N): - import random, string - return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N)) - - +from processor import random_string def get_version(request): @@ -259,7 +255,6 @@ class StratumJSONRPCServer(SocketServer.TCPServer, StratumJSONRPCDispatcher): self.sessions = {} - def create_session(self): session_id = random_string(10) self.sessions[session_id] = HttpSession(session_id) @@ -283,7 +278,8 @@ class HttpSession(Session): def __init__(self, session_id): Session.__init__(self) self.pending_responses = Queue.Queue() - print "new http session", session_id + self.address = session_id + self.name = "HTTP session" def send_response(self, response): raw_response = json.dumps(response) diff --git a/transports/stratum_tcp.py b/transports/stratum_tcp.py index ab6c5c3..cb0f203 100644 --- a/transports/stratum_tcp.py +++ b/transports/stratum_tcp.py @@ -4,15 +4,16 @@ import threading import time import Queue as queue -from processor import Session, Dispatcher +from processor import Session, Dispatcher, timestr class TcpSession(Session): def __init__(self, connection, address): - self._connection = connection - self.address = address Session.__init__(self) - print "New session", address + self._connection = connection + self.address = address[0] + self.version = 'unknown' + self.name = "TCP session" def connection(self): if self.stopped(): @@ -22,7 +23,7 @@ class TcpSession(Session): def stop(self): self._connection.close() - print "Terminating connection:", self.address[0] + #print "Terminating connection:", self.address with self.lock: self._stopped = True