From 3a419b12c208727606d1e309ad2688a5d2e7ceb2 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 23 Feb 2016 14:37:06 +0530 Subject: [PATCH] log less --- oml/nodes.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/oml/nodes.py b/oml/nodes.py index 515fda4..36689a3 100644 --- a/oml/nodes.py +++ b/oml/nodes.py @@ -31,7 +31,7 @@ import library import logging logger = logging.getLogger(__name__) -ENCODING='base64' +DEBUG_NODES=False class Node(Thread): host = None @@ -185,10 +185,12 @@ class Node(Thread): logger.debug('version does not match local: %s remote %s', settings.NODE_PROTOCOL, version) return False c = r.read() - logger.debug('can connect to: %s', url) + if DEBUG_NODES: + logger.debug('can connect to: %s', url) return True except: - logger.debug('can not connect to: %s', url) + if DEBUG_NODES: + logger.debug('can not connect to: %s', url) pass return False @@ -202,13 +204,16 @@ class Node(Thread): with db.session(): u = user.models.User.get_or_create(self.user_id) if u.peered or u.queued: - logger.debug('go online peered=%s queued=%s %s (%s)', u.peered, u.queued, u.id, u.nickname) + if DEBUG_NODES: + logger.debug('go online peered=%s queued=%s %s (%s)', u.peered, u.queued, u.id, u.nickname) try: self.online = self.can_connect() if self.online: - logger.debug('connected to %s', self.url) + if DEBUG_NODES: + logger.debug('connected to %s', self.url) if u.queued: - logger.debug('queued peering event pending=%s peered=%s', u.pending, u.peered) + if DEBUG_NODES: + logger.debug('queued peering event pending=%s peered=%s', u.pending, u.peered) if u.pending == 'sent': self.peering('requestPeering') elif u.pending == '' and u.peered: @@ -217,7 +222,8 @@ class Node(Thread): #fixme, what about cancel/reject peering here? self.peering('removePeering') except: - logger.debug('failed to connect to %s', self.user_id) + if DEBUG_NODES: + logger.debug('failed to connect to %s', self.user_id) self.online = False def trigger_status(self): @@ -238,7 +244,8 @@ class Node(Thread): changes = self.request('pullChanges', from_revision) except: self.online = False - logger.debug('%s went offline', u.name, exc_info=True) + if DEBUG_NODES: + logger.debug('%s went offline', u.name, exc_info=True) return False if not changes: return False @@ -275,7 +282,8 @@ class Node(Thread): self.resolve() url = '%s/get/%s' % (self.url, item.id) t1 = datetime.utcnow() - logger.debug('download %s', url) + if DEBUG_NODES: + logger.debug('download %s', url) self._opener.addheaders = list(zip(self.headers.keys(), self.headers.values())) try: r = self._opener.open(url, timeout=self.TIMEOUT*5) @@ -340,7 +348,8 @@ class Node(Thread): def download_preview(self, item_id): from item.icons import icons self.resolve() - logger.debug('download preview for %s from %s', item_id, self.url) + if DEBUG_NODES: + logger.debug('download preview for %s from %s', item_id, self.url) url = '%s/preview/%s' % (self.url, item_id) self._opener.addheaders = list(zip(self.headers.keys(), self.headers.values())) try: