parent
8beb6c32f6
commit
3afa403a08
@ -36,6 +36,7 @@ import sys
|
||||
from collections import Container, Mapping
|
||||
from struct import pack, Struct
|
||||
|
||||
# Logging utilities
|
||||
|
||||
class ConnectionLogger(logging.LoggerAdapter):
|
||||
'''Prepends a connection identifier to a logging message.'''
|
||||
@ -44,6 +45,20 @@ class ConnectionLogger(logging.LoggerAdapter):
|
||||
return f'[{conn_id}] {msg}', kwargs
|
||||
|
||||
|
||||
class CompactFormatter(logging.Formatter):
|
||||
'''Strips the module from the logger name to leave the class only.'''
|
||||
def format(self, record):
|
||||
record.name = record.name.rpartition('.')[-1]
|
||||
return super().format(record)
|
||||
|
||||
|
||||
def make_logger(name, *, handler, level):
|
||||
logger = logging.getLogger(name)
|
||||
logger.addHandler(handler)
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.propagate = False
|
||||
return logger
|
||||
|
||||
# Method decorator. To be used for calculations that will always
|
||||
# deliver the same result. The method cannot take any arguments
|
||||
# and should be accessed as an attribute.
|
||||
|
||||
@ -10,15 +10,20 @@
|
||||
'''Script to kick off the server.'''
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from electrumx import Controller, Env
|
||||
from electrumx.lib.util import CompactFormatter, make_logger
|
||||
|
||||
|
||||
def main():
|
||||
'''Set up logging and run the server.'''
|
||||
log_fmt = Env.default('LOG_FORMAT', '%(levelname)s:%(name)s:%(message)s')
|
||||
logging.basicConfig(level=logging.INFO, format=log_fmt)
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
handler.setFormatter(CompactFormatter(log_fmt))
|
||||
make_logger('electrumx', handler=handler, level=logging.INFO)
|
||||
|
||||
logging.info('ElectrumX server starting')
|
||||
try:
|
||||
controller = Controller(Env())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user