From d82f44190e60bf5807c4a679079dc9a6207d8488 Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Wed, 26 Jul 2017 21:52:48 +0300 Subject: [PATCH] Implement logging levels By default log level is INFO if not set in config, can be changed (this repeats functionality from joinmarket-org/joinmarket). --- jmbase/jmbase/__init__.py | 3 ++- jmbase/jmbase/support.py | 3 +++ jmclient/jmclient/configure.py | 14 +++++++++++++- jmdaemon/jmdaemon/irc.py | 5 +++-- jmdaemon/jmdaemon/message_channel.py | 3 ++- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/jmbase/jmbase/__init__.py b/jmbase/jmbase/__init__.py index 351cd64..240d925 100644 --- a/jmbase/jmbase/__init__.py +++ b/jmbase/jmbase/__init__.py @@ -1,6 +1,7 @@ from __future__ import print_function from .support import (get_log, chunks, debug_silence, debug_dump_object, - joinmarket_alert, core_alert, get_password, _byteify) + joinmarket_alert, core_alert, get_password, _byteify, + set_logging_level) from commands import * diff --git a/jmbase/jmbase/support.py b/jmbase/jmbase/support.py index fe78b46..a975fe6 100644 --- a/jmbase/jmbase/support.py +++ b/jmbase/jmbase/support.py @@ -45,6 +45,9 @@ def get_log(): """ return log +def set_logging_level(level): + consoleHandler.setLevel(level) + def chunks(d, n): return [d[x:x + n] for x in xrange(0, len(d), n)] diff --git a/jmclient/jmclient/configure.py b/jmclient/jmclient/configure.py index 29570a0..f13e874 100644 --- a/jmclient/jmclient/configure.py +++ b/jmclient/jmclient/configure.py @@ -11,7 +11,8 @@ from ConfigParser import SafeConfigParser, NoOptionError import btc from jmclient.jsonrpc import JsonRpc -from jmbase.support import get_log, joinmarket_alert, core_alert, debug_silence +from jmbase.support import (get_log, joinmarket_alert, core_alert, debug_silence, + set_logging_level) from jmclient.podle import set_commitment_file log = get_log() @@ -131,6 +132,12 @@ socks5_port = 9050, 9050 #usessl = true, false #socks5 = true, true +[LOGGING] +# Set the log level for the output to the terminal/console +# Possible choices: DEBUG / INFO / WARNING / ERROR +# Log level for the files in the logs-folder will always be DEBUG +console_log_level = INFO + [TIMEOUT] maker_timeout_sec = 30 unconfirm_timeout_sec = 90 @@ -313,6 +320,11 @@ def load_program_config(config_path=None, bs=None): raise Exception( "Config file does not contain the required option: " + o) + loglevel = global_singleton.config.get("LOGGING", "console_log_level") + try: + set_logging_level(loglevel) + except: + print("Failed to set logging level, must be DEBUG, INFO, WARNING, ERROR") try: global_singleton.maker_timeout_sec = global_singleton.config.getint( 'TIMEOUT', 'maker_timeout_sec') diff --git a/jmdaemon/jmdaemon/irc.py b/jmdaemon/jmdaemon/irc.py index 8194b5c..9956fef 100644 --- a/jmdaemon/jmdaemon/irc.py +++ b/jmdaemon/jmdaemon/irc.py @@ -12,6 +12,8 @@ from twisted.internet.endpoints import TCP4ClientEndpoint from twisted.internet.ssl import ClientContextFactory from twisted.logger import Logger from twisted.words.protocols import irc +from twisted.internet.error import (ConnectionLost, ConnectionAborted, + ConnectionClosed, ConnectionDone) from jmdaemon.message_channel import MessageChannel from jmbase.support import get_log, chunks from txsocksx.client import SOCKS5ClientEndpoint @@ -54,7 +56,7 @@ class TxIRCFactory(protocol.ClientFactory): return p def clientConnectionLost(self, connector, reason): - log.info('IRC connection lost: ' + str(reason)) + log.debug('IRC connection lost: ' + str(reason)) if not self.wrapper.give_up: if reactor.running: log.info('Attempting to reconnect...') @@ -182,7 +184,6 @@ class txIRC_Client(irc.IRCClient, object): return irc.IRCClient.connectionMade(self) def connectionLost(self, reason=protocol.connectionDone): - wlog('connectionLost:') if self.wrapper.on_disconnect: reactor.callLater(0.0, self.wrapper.on_disconnect, self.wrapper) return irc.IRCClient.connectionLost(self, reason) diff --git a/jmdaemon/jmdaemon/message_channel.py b/jmdaemon/jmdaemon/message_channel.py index c08088d..11725aa 100644 --- a/jmdaemon/jmdaemon/message_channel.py +++ b/jmdaemon/jmdaemon/message_channel.py @@ -17,7 +17,8 @@ class CJPeerError(StandardError): class MChannelThread(threading.Thread): - + """Class used only in testing. + """ def __init__(self, mc): threading.Thread.__init__(self, name='MCThread') self.daemon = True