Merge pull request #779 from lbryio/fix-loggly

Fix loggly
This commit is contained in:
Jack Robison 2017-07-14 14:42:47 -04:00 committed by GitHub
commit aced5b6499
5 changed files with 42 additions and 36 deletions

View file

@ -12,7 +12,6 @@ at anytime.
* Add link to instructions on how to change the default peer port
* Add `peer_port` to settings configurable using `settings_set`
* Added an option to disable max key fee check.
*
### Changed
*
@ -21,6 +20,8 @@ at anytime.
### Fixed
* Fix for https://github.com/lbryio/lbry/issues/750
*
* Fixed daemon process hanging when started without an internet connection
* Fixed https://github.com/lbryio/lbry/issues/774
### Deprecated
*

View file

@ -145,7 +145,7 @@ FIXED_SETTINGS = {
},
'DB_REVISION_FILE_NAME': 'db_revision',
'ICON_PATH': ICON_PATH,
'LOGGLY_TOKEN': 'LJEzATH4AzRgAwxjAP00LwZ2YGx3MwVgZTMuBQZ3MQuxLmOv',
'LOGGLY_TOKEN': 'BQEzZmMzLJHgAGxkBF00LGD0YGuyATVgAmqxAQEuAQZ2BQH4',
'LOG_FILE_NAME': 'lbrynet.log',
'LOG_POST_URL': 'https://lbry.io/log-upload',
'MAX_BLOB_REQUEST_SIZE': 64 * KB,

View file

@ -7,6 +7,8 @@ import sys
import traceback
from txrequests import Session
from requests.exceptions import ConnectionError
from twisted.internet import defer
import twisted.python.log
from lbrynet import __version__ as lbrynet_version, build_type, conf
@ -32,11 +34,6 @@ _srcfile = os.path.normcase(_srcfile)
TRACE = 5
def bg_cb(sess, resp):
""" Don't do anything with the response """
pass
class HTTPSHandler(logging.Handler):
def __init__(self, url, fqdn=False, localname=None, facility=None, session=None):
logging.Handler.__init__(self)
@ -52,14 +49,16 @@ class HTTPSHandler(logging.Handler):
else:
return record.getMessage()
def emit(self, record):
try:
@defer.inlineCallbacks
def _emit(self, record):
payload = self.format(record)
self.session.post(self.url, data=payload, background_callback=bg_cb)
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
try:
yield self.session.post(self.url, data=payload)
except ConnectionError:
pass
def emit(self, record):
return self._emit(record)
DEFAULT_FORMAT = "%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s"
@ -109,11 +108,11 @@ def configure_handler(handler, log, level):
def disable_third_party_loggers():
logging.getLogger('requests').setLevel(logging.WARNING)
logging.getLogger('urllib3').setLevel(logging.WARNING)
logging.getLogger('requests').setLevel(logging.CRITICAL)
logging.getLogger('urllib3').setLevel(logging.CRITICAL)
logging.getLogger('BitcoinRPC').setLevel(logging.INFO)
logging.getLogger('lbryum').setLevel(logging.WARNING)
logging.getLogger('twisted').setLevel(logging.WARNING)
logging.getLogger('twisted').setLevel(logging.CRITICAL)
@_log_decorator
@ -140,18 +139,27 @@ def get_loggly_url(token=None, version=None):
return LOGGLY_URL.format(token=token, tag='lbrynet-' + version)
def configure_loggly_handler(*args, **kwargs):
def configure_loggly_handler():
if build_type.BUILD == 'dev':
return
level = kwargs.pop('level', logging.WARNING)
_configure_loggly_handler(*args, level=level, **kwargs)
level = logging.WARNING
handler = get_loggly_handler(level=level, installation_id=conf.settings.installation_id,
session_id=conf.settings.get_session_id())
log = logging.getLogger("lbrynet")
if handler.name:
remove_handlers(log, handler.name)
handler.setLevel(level)
log.addHandler(handler)
# need to reduce the logger's level down to the
# handler's level or else the handler won't
# get those messages
if log.level > level:
log.setLevel(level)
@_log_decorator
def _configure_loggly_handler(url=None, **kwargs):
url = url or get_loggly_url()
formatter = JsonFormatter(**kwargs)
handler = HTTPSHandler(url)
def get_loggly_handler(level, installation_id, session_id):
formatter = JsonFormatter(level=level, installation_id=installation_id, session_id=session_id)
handler = HTTPSHandler(get_loggly_url())
handler.setFormatter(formatter)
handler.name = 'loggly'
return handler
@ -256,7 +264,6 @@ def configure_logging(file_name, console, verbose=None):
verbose = convert_verbose(verbose)
configure_twisted()
configure_file_handler(file_name)
configure_loggly_handler()
disable_third_party_loggers()
if console:
# if there are some loggers at the debug level, we need

View file

@ -24,7 +24,7 @@ from lbrynet import conf, analytics
from lbrynet.conf import LBRYCRD_WALLET, LBRYUM_WALLET, PTC_WALLET
from lbrynet.reflector import reupload
from lbrynet.reflector import ServerFactory as reflector_server_factory
from lbrynet.core.log_support import configure_loggly_handler
from lbrynet.lbry_file.client.EncryptedFileDownloader import EncryptedFileSaverFactory
from lbrynet.lbry_file.client.EncryptedFileDownloader import EncryptedFileOpenerFactory
from lbrynet.lbry_file.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
@ -36,7 +36,7 @@ from lbrynet.daemon.Publisher import Publisher
from lbrynet.daemon.ExchangeRateManager import ExchangeRateManager
from lbrynet.daemon.auth.server import AuthJSONRPCServer
from lbrynet.core.PaymentRateManager import OnlyFreePaymentsManager
from lbrynet.core import log_support, utils, system_info
from lbrynet.core import utils, system_info
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob
from lbrynet.core.Session import Session
from lbrynet.core.Wallet import LBRYumWallet, SqliteStorage, ClaimOutpoint
@ -225,7 +225,7 @@ class Daemon(AuthJSONRPCServer):
def setup(self):
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
self._modify_loggly_formatter()
configure_loggly_handler()
@defer.inlineCallbacks
def _announce_startup():
@ -505,12 +505,6 @@ class Daemon(AuthJSONRPCServer):
return d
return defer.succeed(True)
def _modify_loggly_formatter(self):
log_support.configure_loggly_handler(
installation_id=conf.settings.installation_id,
session_id=self._session_id
)
@defer.inlineCallbacks
def _setup_lbry_file_manager(self):
log.info('Starting to setup up file manager')

View file

@ -367,7 +367,11 @@ class KademliaProtocol(protocol.DatagramProtocol):
# i'm scared this may swallow important errors, but i get a million of these
# on Linux and it doesnt seem to affect anything -grin
log.debug("Can't send data to dht: EWOULDBLOCK")
elif err.errno == errno.ENETUNREACH:
# this should probably try to retransmit when the network connection is back
log.error("Network is unreachable")
else:
log.error("DHT socket error: %s (%i)", err.message, err.errno)
raise err
def _sendResponse(self, contact, rpcID, response):