Browse Source

Implement logging levels

By default log level is INFO if not set in config, can be changed
(this repeats functionality from joinmarket-org/joinmarket).
master
Adam Gibson 9 years ago
parent
commit
d82f44190e
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 3
      jmbase/jmbase/__init__.py
  2. 3
      jmbase/jmbase/support.py
  3. 14
      jmclient/jmclient/configure.py
  4. 5
      jmdaemon/jmdaemon/irc.py
  5. 3
      jmdaemon/jmdaemon/message_channel.py

3
jmbase/jmbase/__init__.py

@ -1,6 +1,7 @@
from __future__ import print_function from __future__ import print_function
from .support import (get_log, chunks, debug_silence, debug_dump_object, 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 * from commands import *

3
jmbase/jmbase/support.py

@ -45,6 +45,9 @@ def get_log():
""" """
return log return log
def set_logging_level(level):
consoleHandler.setLevel(level)
def chunks(d, n): def chunks(d, n):
return [d[x:x + n] for x in xrange(0, len(d), n)] return [d[x:x + n] for x in xrange(0, len(d), n)]

14
jmclient/jmclient/configure.py

@ -11,7 +11,8 @@ from ConfigParser import SafeConfigParser, NoOptionError
import btc import btc
from jmclient.jsonrpc import JsonRpc 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 from jmclient.podle import set_commitment_file
log = get_log() log = get_log()
@ -131,6 +132,12 @@ socks5_port = 9050, 9050
#usessl = true, false #usessl = true, false
#socks5 = true, true #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] [TIMEOUT]
maker_timeout_sec = 30 maker_timeout_sec = 30
unconfirm_timeout_sec = 90 unconfirm_timeout_sec = 90
@ -313,6 +320,11 @@ def load_program_config(config_path=None, bs=None):
raise Exception( raise Exception(
"Config file does not contain the required option: " + o) "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: try:
global_singleton.maker_timeout_sec = global_singleton.config.getint( global_singleton.maker_timeout_sec = global_singleton.config.getint(
'TIMEOUT', 'maker_timeout_sec') 'TIMEOUT', 'maker_timeout_sec')

5
jmdaemon/jmdaemon/irc.py

@ -12,6 +12,8 @@ from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.internet.ssl import ClientContextFactory from twisted.internet.ssl import ClientContextFactory
from twisted.logger import Logger from twisted.logger import Logger
from twisted.words.protocols import irc from twisted.words.protocols import irc
from twisted.internet.error import (ConnectionLost, ConnectionAborted,
ConnectionClosed, ConnectionDone)
from jmdaemon.message_channel import MessageChannel from jmdaemon.message_channel import MessageChannel
from jmbase.support import get_log, chunks from jmbase.support import get_log, chunks
from txsocksx.client import SOCKS5ClientEndpoint from txsocksx.client import SOCKS5ClientEndpoint
@ -54,7 +56,7 @@ class TxIRCFactory(protocol.ClientFactory):
return p return p
def clientConnectionLost(self, connector, reason): 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 not self.wrapper.give_up:
if reactor.running: if reactor.running:
log.info('Attempting to reconnect...') log.info('Attempting to reconnect...')
@ -182,7 +184,6 @@ class txIRC_Client(irc.IRCClient, object):
return irc.IRCClient.connectionMade(self) return irc.IRCClient.connectionMade(self)
def connectionLost(self, reason=protocol.connectionDone): def connectionLost(self, reason=protocol.connectionDone):
wlog('connectionLost:')
if self.wrapper.on_disconnect: if self.wrapper.on_disconnect:
reactor.callLater(0.0, self.wrapper.on_disconnect, self.wrapper) reactor.callLater(0.0, self.wrapper.on_disconnect, self.wrapper)
return irc.IRCClient.connectionLost(self, reason) return irc.IRCClient.connectionLost(self, reason)

3
jmdaemon/jmdaemon/message_channel.py

@ -17,7 +17,8 @@ class CJPeerError(StandardError):
class MChannelThread(threading.Thread): class MChannelThread(threading.Thread):
"""Class used only in testing.
"""
def __init__(self, mc): def __init__(self, mc):
threading.Thread.__init__(self, name='MCThread') threading.Thread.__init__(self, name='MCThread')
self.daemon = True self.daemon = True

Loading…
Cancel
Save