obelisk

Electrum server using libbitcoin as its backend
git clone https://git.parazyd.org/obelisk
Log | Files | Refs | README | LICENSE

commit f63d6b87ae4ef3469f6066718700ca6f821f7a42
parent 4c6e004e8dea235f41dd48d71e4753acab31f29f
Author: parazyd <parazyd@dyne.org>
Date:   Fri,  9 Apr 2021 15:34:46 +0200

Clean up logging methods.

Diffstat:
Mobelisk.py | 39++++++++++-----------------------------
Mres/obelisk.cfg | 16++++++++--------
2 files changed, 18 insertions(+), 37 deletions(-)

diff --git a/obelisk.py b/obelisk.py @@ -18,9 +18,8 @@ import asyncio import sys from argparse import ArgumentParser from configparser import RawConfigParser, NoSectionError -from logging import getLogger, FileHandler, Formatter, StreamHandler, DEBUG -from os.path import join -from tempfile import gettempdir +from logging import getLogger, FileHandler, Formatter, StreamHandler +from os import devnull from electrumobelisk.protocol import ElectrumProtocol, VERSION @@ -30,29 +29,19 @@ PROTOCOL = None def logger_config(log, config): """Setup logging""" - fmt = Formatter( - config.get( - "obelisk", - "log_format", - fallback="%(asctime)s\t%(levelname)s\t%(message)s", - )) + fmt = Formatter("%(asctime)s\t%(levelname)s\t%(message)s") logstream = StreamHandler() logstream.setFormatter(fmt) - logstream.setLevel( - config.get("obelisk", "log_level_stdout", fallback="DEBUG")) + debuglevel = config.get("obelisk", "log_level", fallback="INFO") + logstream.setLevel(debuglevel) log.addHandler(logstream) - filename = config.get("obelisk", "log_file_location", fallback="") - if len(filename.strip()) == 0: - filename = join(gettempdir(), "obelisk.log") - logfile = FileHandler( - filename, - mode=("a" if config.get("obelisk", "append_log", fallback="false") else - "w"), - ) + filename = config.get("obelisk", "log_file", fallback=devnull) + append_log = config.getboolean("obelisk", "append_log", fallback=False) + logfile = FileHandler(filename, mode=("a" if append_log else "w")) logfile.setFormatter(fmt) - logfile.setLevel(DEBUG) + logfile.setLevel(debuglevel) log.addHandler(logfile) - log.setLevel(DEBUG) + log.setLevel(debuglevel) return log, filename @@ -62,12 +51,6 @@ async def run_electrum_server(config, chain): host = config.get("obelisk", "host") port = int(config.get("obelisk", "port")) - broadcast_method = config.get("obelisk", - "broadcast_method", - fallback="tor") - tor_host = config.get("obelisk", "tor_host", fallback="localhost") - tor_port = int(config.get("obelisk", "tor_port", fallback=9050)) - endpoints = {} endpoints["query"] = config.get("obelisk", "query") endpoints["heart"] = config.get("obelisk", "heart") @@ -75,8 +58,6 @@ async def run_electrum_server(config, chain): endpoints["trans"] = config.get("obelisk", "trans") server_cfg = {} - server_cfg["torhostport"] = (tor_host, tor_port) - server_cfg["broadcast_method"] = broadcast_method server_cfg["server_hostname"] = "localhost" # TODO: <- should be public? server_cfg["server_port"] = port diff --git a/res/obelisk.cfg b/res/obelisk.cfg @@ -8,16 +8,16 @@ port = 50003 chain = testnet # Endpoints served by bs -#query = tcp://localhost:9091 -#heart = tcp://localhost:9092 -#block = tcp://localhost:9093 -#trans = tcp://localhost:9094 query = tcp://testnet2.libbitcoin.net:29091 heart = tcp://testnet2.libbitcoin.net:29092 block = tcp://testnet2.libbitcoin.net:29093 trans = tcp://testnet2.libbitcoin.net:29094 -# Space-separated whitelist of IP addresses -# Accepts CIDR notation, e.g. 192.168.0.0/16 or 2a01:4f8:1f1::/120 -# Wildcard (*) means all are accepted (Generally requires host to be 0.0.0.0) -ip_whitelist = * +# Log level (INFO/WARNING/DEBUG) +log_level = DEBUG + +# Path to log file for writing +#log_file = obelisk.log + +# Append to logfile +#append_log = true