better log names

This commit is contained in:
Alex Grintsvayg 2016-05-20 19:59:49 -04:00
parent 098b5b28a8
commit f48c1562f3

View file

@ -397,9 +397,9 @@ class LBRYDaemon(jsonrpc.JSONRPC):
# self.lbrynet_connection_checker.start(3600) # self.lbrynet_connection_checker.start(3600)
if self.first_run: if self.first_run:
d = self._upload_log(name_prefix="fr") d = self._upload_log(log_type="first_run")
else: else:
d = self._upload_log(exclude_previous=True, name_prefix="start") d = self._upload_log(exclude_previous=True, log_type="start")
if float(self.session.wallet.wallet_balance) == 0.0: if float(self.session.wallet.wallet_balance) == 0.0:
d.addCallback(lambda _: self._check_first_run()) d.addCallback(lambda _: self._check_first_run())
@ -579,12 +579,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
dl.addCallback(_set_query_handlers) dl.addCallback(_set_query_handlers)
return dl return dl
def _upload_log(self, name_prefix=None, exclude_previous=False, force=False): def _upload_log(self, log_type=None, exclude_previous=False, force=False):
if name_prefix:
name_prefix = name_prefix + "-" + platform.system()
else:
name_prefix = platform.system()
if self.upload_log or force: if self.upload_log or force:
LOG_URL = "https://lbry.io/log-upload" LOG_URL = "https://lbry.io/log-upload"
if exclude_previous: if exclude_previous:
@ -596,9 +591,13 @@ class LBRYDaemon(jsonrpc.JSONRPC):
f = open(self.log_file, "r") f = open(self.log_file, "r")
log_contents = f.read() log_contents = f.read()
f.close() f.close()
t = datetime.now() params = {
log_name = name_prefix + "-" + base58.b58encode(self.lbryid)[:20] + "-" + str(t.month) + "-" + str(t.day) + "-" + str(t.year) + "-" + str(t.hour) + "-" + str(t.minute) 'date': datetime.utcnow().strftime('%Y%m%d-%H%M%S'),
params = {'name': log_name, 'log': log_contents} 'hash': base58.b58encode(self.lbryid)[:20],
'sys': platform.system(),
'type': log_type,
'log': log_contents
}
requests.post(LOG_URL, params) requests.post(LOG_URL, params)
return defer.succeed(None) return defer.succeed(None)
@ -609,7 +608,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
log.info("Closing lbrynet session") log.info("Closing lbrynet session")
log.info("Status at time of shutdown: " + self.startup_status[0]) log.info("Status at time of shutdown: " + self.startup_status[0])
d = self._upload_log(name_prefix="close", exclude_previous=False if self.first_run else True) d = self._upload_log(log_type="close", exclude_previous=False if self.first_run else True)
d.addCallback(lambda _: self._stop_server()) d.addCallback(lambda _: self._stop_server())
d.addCallback(lambda _: self.lbry_file_manager.stop()) d.addCallback(lambda _: self.lbry_file_manager.stop())
d.addErrback(lambda err: log.info("Bad server shutdown: " + err.getTraceback())) d.addErrback(lambda err: log.info("Bad server shutdown: " + err.getTraceback()))
@ -2084,9 +2083,9 @@ class LBRYDaemon(jsonrpc.JSONRPC):
if p: if p:
if 'name_prefix' in p.keys(): if 'name_prefix' in p.keys():
prefix = p['name_prefix'] + '_api' log_type = p['name_prefix'] + '_api'
else: else:
prefix = None log_type = None
if 'exclude_previous' in p.keys(): if 'exclude_previous' in p.keys():
exclude_previous = p['exclude_previous'] exclude_previous = p['exclude_previous']
@ -2101,10 +2100,10 @@ class LBRYDaemon(jsonrpc.JSONRPC):
else: else:
force = False force = False
else: else:
prefix = "api" log_type = "api"
exclude_previous = True exclude_previous = True
d = self._upload_log(name_prefix=prefix, exclude_previous=exclude_previous, force=force) d = self._upload_log(log_type=log_type, exclude_previous=exclude_previous, force=force)
if 'message' in p.keys(): if 'message' in p.keys():
d.addCallback(lambda _: self._log_to_slack(p['message'])) d.addCallback(lambda _: self._log_to_slack(p['message']))
d.addCallback(lambda _: self._render_response(True, OK_CODE)) d.addCallback(lambda _: self._render_response(True, OK_CODE))