log to file
This commit is contained in:
parent
1e3087953f
commit
32a2e92993
5 changed files with 34 additions and 20 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -7,14 +8,16 @@ from scribe.blockchain.service import BlockchainProcessorService
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
setup_logging()
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog='scribe'
|
prog='scribe'
|
||||||
)
|
)
|
||||||
Env.contribute_to_arg_parser(parser)
|
Env.contribute_to_arg_parser(parser)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
block_processor = BlockchainProcessorService(Env.from_arg_parser(args))
|
env = Env.from_arg_parser(args)
|
||||||
|
setup_logging(os.path.join(env.db_dir, 'scribe.log'))
|
||||||
|
block_processor = BlockchainProcessorService(env)
|
||||||
block_processor.run()
|
block_processor.run()
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
|
@ -2,6 +2,7 @@ import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import logging
|
import logging
|
||||||
|
import logging.handlers
|
||||||
import typing
|
import typing
|
||||||
import collections
|
import collections
|
||||||
from asyncio import get_event_loop, Event
|
from asyncio import get_event_loop, Event
|
||||||
|
@ -23,8 +24,17 @@ HISTOGRAM_BUCKETS = (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup_logging():
|
def setup_logging(log_path: str):
|
||||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)-4s %(name)s:%(lineno)d: %(message)s")
|
log = logging.getLogger('scribe')
|
||||||
|
fmt = logging.Formatter("%(asctime)s %(levelname)-4s %(name)s:%(lineno)d: %(message)s")
|
||||||
|
handler = logging.handlers.RotatingFileHandler(log_path, maxBytes=1024*1024*5, backupCount=2)
|
||||||
|
handler.setFormatter(fmt)
|
||||||
|
log.addHandler(handler)
|
||||||
|
handler = logging.StreamHandler()
|
||||||
|
handler.setFormatter(fmt)
|
||||||
|
log.addHandler(handler)
|
||||||
|
|
||||||
|
log.setLevel(logging.INFO)
|
||||||
logging.getLogger('aiohttp').setLevel(logging.WARNING)
|
logging.getLogger('aiohttp').setLevel(logging.WARNING)
|
||||||
logging.getLogger('elasticsearch').setLevel(logging.WARNING)
|
logging.getLogger('elasticsearch').setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -7,7 +8,6 @@ from scribe.elasticsearch.service import ElasticSyncService
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
setup_logging()
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog='scribe-elastic-sync'
|
prog='scribe-elastic-sync'
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,9 @@ def main():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
server = ElasticSyncService(Env.from_arg_parser(args))
|
env = Env.from_arg_parser(args)
|
||||||
|
setup_logging(os.path.join(env.db_dir, 'scribe-elastic-sync.log'))
|
||||||
|
server = ElasticSyncService(env)
|
||||||
server.run(args.reindex)
|
server.run(args.reindex)
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -7,7 +8,6 @@ from scribe.hub.service import HubServerService
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
setup_logging()
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog='scribe-hub'
|
prog='scribe-hub'
|
||||||
)
|
)
|
||||||
|
@ -15,8 +15,9 @@ def main():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
env = Env.from_arg_parser(args)
|
||||||
server = HubServerService(Env.from_arg_parser(args))
|
setup_logging(os.path.join(env.db_dir, 'scribe-hub.log'))
|
||||||
|
server = HubServerService(env)
|
||||||
server.run()
|
server.run()
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
|
@ -215,8 +215,7 @@ class SessionManager:
|
||||||
protocol_class = LBRYElectrumX
|
protocol_class = LBRYElectrumX
|
||||||
else:
|
else:
|
||||||
raise ValueError(kind)
|
raise ValueError(kind)
|
||||||
protocol_factory = partial(protocol_class, self, self.db,
|
protocol_factory = partial(protocol_class, self, kind)
|
||||||
self.mempool, kind)
|
|
||||||
|
|
||||||
host, port = args[:2]
|
host, port = args[:2]
|
||||||
try:
|
try:
|
||||||
|
@ -666,7 +665,7 @@ class LBRYElectrumX(asyncio.Protocol):
|
||||||
)
|
)
|
||||||
max_errors = 10
|
max_errors = 10
|
||||||
|
|
||||||
def __init__(self, session_manager: SessionManager, db: 'HubDB', mempool: 'MemPool', kind: str):
|
def __init__(self, session_manager: SessionManager, kind: str):
|
||||||
connection = JSONRPCConnection(JSONRPCAutoDetect)
|
connection = JSONRPCConnection(JSONRPCAutoDetect)
|
||||||
self.env = session_manager.env
|
self.env = session_manager.env
|
||||||
self.framer = self.default_framer()
|
self.framer = self.default_framer()
|
||||||
|
@ -700,8 +699,7 @@ class LBRYElectrumX(asyncio.Protocol):
|
||||||
|
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
self.session_manager = session_manager
|
self.session_manager = session_manager
|
||||||
self.db = db
|
|
||||||
self.mempool = mempool
|
|
||||||
self.kind = kind # 'RPC', 'TCP' etc.
|
self.kind = kind # 'RPC', 'TCP' etc.
|
||||||
self.coin = self.env.coin
|
self.coin = self.env.coin
|
||||||
self.anon_logs = self.env.anon_logs
|
self.anon_logs = self.env.anon_logs
|
||||||
|
@ -719,8 +717,10 @@ class LBRYElectrumX(asyncio.Protocol):
|
||||||
self.sv_seen = False
|
self.sv_seen = False
|
||||||
self.protocol_tuple = self.PROTOCOL_MIN
|
self.protocol_tuple = self.PROTOCOL_MIN
|
||||||
self.protocol_string = None
|
self.protocol_string = None
|
||||||
|
|
||||||
self.daemon = self.session_manager.daemon
|
self.daemon = self.session_manager.daemon
|
||||||
self.db: 'HubDB' = self.session_manager.db
|
self.db = self.session_manager.db
|
||||||
|
self.mempool = self.session_manager.mempool
|
||||||
|
|
||||||
def data_received(self, framed_message):
|
def data_received(self, framed_message):
|
||||||
"""Called by asyncio when a message comes in."""
|
"""Called by asyncio when a message comes in."""
|
||||||
|
@ -757,13 +757,11 @@ class LBRYElectrumX(asyncio.Protocol):
|
||||||
self._pm_task = self.loop.create_task(self._receive_messages())
|
self._pm_task = self.loop.create_task(self._receive_messages())
|
||||||
|
|
||||||
self.session_id = next(self.session_counter)
|
self.session_id = next(self.session_counter)
|
||||||
context = {'conn_id': f'{self.session_id}'}
|
# context = {'conn_id': f'{self.session_id}'}
|
||||||
self.logger = logging.getLogger(__name__) # util.ConnectionLogger(self.logger, context)
|
# self.logger = logging.getLogger(__name__) # util.ConnectionLogger(self.logger, context)
|
||||||
self.group = self.session_manager.add_session(self)
|
self.group = self.session_manager.add_session(self)
|
||||||
self.session_manager.session_count_metric.labels(version=self.client_version).inc()
|
self.session_manager.session_count_metric.labels(version=self.client_version).inc()
|
||||||
peer_addr_str = self.peer_address_str()
|
# self.logger.info(f'{self.kind} {self.peer_address_str()}, {self.session_manager.session_count():,d} total')
|
||||||
self.logger.info(f'{self.kind} {peer_addr_str}, '
|
|
||||||
f'{self.session_manager.session_count():,d} total')
|
|
||||||
|
|
||||||
def connection_lost(self, exc):
|
def connection_lost(self, exc):
|
||||||
"""Handle client disconnection."""
|
"""Handle client disconnection."""
|
||||||
|
|
Loading…
Reference in a new issue