lbryum logging in lbryum.log, add to upload_log()

This commit is contained in:
Jack 2016-06-04 17:05:14 -04:00
parent 85b56247a3
commit 20ca2eac37
9 changed files with 66 additions and 110 deletions

View file

@ -1,8 +1,29 @@
import logging
import sys
import os
from lbrynet.conf import LOG_FILE_NAME
from appdirs import user_data_dir
if sys.platform != "darwin":
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
else:
log_dir = user_data_dir("LBRY")
logging.getLogger(__name__).addHandler(logging.NullHandler())
if not os.path.isdir(log_dir):
os.mkdir(log_dir)
LOG_PATH = os.path.join(log_dir, LOG_FILE_NAME)
if os.path.isfile(LOG_PATH):
f = open(LOG_PATH, 'r')
PREVIOUS_LOG = len(f.read())
f.close()
else:
PREVIOUS_LOG = 0
log = logging.getLogger(__name__)
log.addHandler(logging.FileHandler(filename=LOG_PATH))
log.setLevel(logging.ERROR)
version = (0, 2, 5)
__version__ = ".".join([str(x) for x in version])

View file

@ -3,9 +3,6 @@ Some network wide and also application specific parameters
"""
import os
MAX_HANDSHAKE_SIZE = 2**16
MAX_REQUEST_SIZE = 2**16
MAX_BLOB_REQUEST_SIZE = 2**16
@ -27,6 +24,7 @@ KNOWN_DHT_NODES = [('104.236.42.182', 4000),
POINTTRADER_SERVER = 'http://ec2-54-187-192-68.us-west-2.compute.amazonaws.com:2424'
#POINTTRADER_SERVER = 'http://127.0.0.1:2424'
LOG_FILE_NAME = "lbrynet.log"
LOG_POST_URL = "https://lbry.io/log-upload"
CRYPTSD_FILE_EXTENSION = ".cryptsd"

View file

@ -40,6 +40,7 @@ from lbrynet.core.utils import generate_id
from lbrynet.lbrynet_console.LBRYSettings import LBRYSettings
from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE, DEFAULT_MAX_SEARCH_RESULTS, KNOWN_DHT_NODES, DEFAULT_MAX_KEY_FEE, \
DEFAULT_WALLET, DEFAULT_SEARCH_TIMEOUT, DEFAULT_CACHE_TIME, DEFAULT_UI_BRANCH, LOG_POST_URL
from lbrynet import LOG_PATH
from lbrynet.conf import DEFAULT_TIMEOUT, WALLET_TYPES
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob
from lbrynet.core.Session import LBRYSession
@ -47,29 +48,23 @@ from lbrynet.core.PTCWallet import PTCWallet
from lbrynet.core.LBRYcrdWallet import LBRYcrdWallet, LBRYumWallet
from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager
from lbrynet.lbryfile.LBRYFileMetadataManager import DBLBRYFileMetadataManager, TempLBRYFileMetadataManager
if sys.platform != "darwin":
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
else:
log_dir = user_data_dir("LBRY")
if not os.path.isdir(log_dir):
os.mkdir(log_dir)
LOG_FILENAME = os.path.join(log_dir, 'lbrynet-daemon.log')
if os.path.isfile(LOG_FILENAME):
f = open(LOG_FILENAME, 'r')
PREVIOUS_LOG = len(f.read())
f.close()
else:
PREVIOUS_LOG = 0
from lbryum.util import LOG_PATH as lbryum_log
from lbrynet import LOG_PATH as lbrynet_log
log = logging.getLogger(__name__)
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5)
log.addHandler(handler)
log.setLevel(logging.INFO)
if os.path.isfile(lbryum_log):
f = open(lbryum_log, 'r')
PREVIOUS_LBRYUM_LOG = len(f.read())
f.close()
else:
PREVIOUS_LBRYUM_LOG = 0
if os.path.isfile(lbrynet_log):
f = open(lbrynet_log, 'r')
PREVIOUS_LBRYNET_LOG = len(f.read())
f.close()
else:
PREVIOUS_LBRYNET_LOG = 0
INITIALIZING_CODE = 'initializing'
LOADING_DB_CODE = 'loading_db'
@ -148,7 +143,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
self.ip = None
self.wallet_type = wallet_type
self.first_run = None
self.log_file = LOG_FILENAME
self.log_file = LOG_PATH
self.current_db_revision = 1
self.run_server = True
self.session = None
@ -625,24 +620,26 @@ class LBRYDaemon(jsonrpc.JSONRPC):
def _upload_log(self, log_type=None, exclude_previous=False, force=False):
if self.upload_log or force:
if exclude_previous:
f = open(self.log_file, "r")
f.seek(PREVIOUS_LOG)
log_contents = f.read()
f.close()
else:
f = open(self.log_file, "r")
log_contents = f.read()
f.close()
params = {
'date': datetime.utcnow().strftime('%Y%m%d-%H%M%S'),
'hash': base58.b58encode(self.lbryid)[:20],
'sys': platform.system(),
'type': log_type if log_type else 'default',
'log': log_contents
}
for lm, lp in [('lbrynet', lbrynet_log), ('lbryum', lbryum_log)]:
if os.path.isfile(lp):
if exclude_previous:
f = open(lp, "r")
f.seek(PREVIOUS_LBRYNET_LOG if lm == 'lbrynet' else PREVIOUS_LBRYUM_LOG)
log_contents = f.read()
f.close()
else:
f = open(lp, "r")
log_contents = f.read()
f.close()
params = {
'date': datetime.utcnow().strftime('%Y%m%d-%H%M%S'),
'hash': base58.b58encode(self.lbryid)[:20],
'sys': platform.system(),
'type': "%s-%s" % (lm, log_type) if log_type else lm,
'log': log_contents
}
requests.post(LOG_POST_URL, params)
requests.post(LOG_POST_URL, params)
return defer.succeed(None)
else:
return defer.succeed(None)

View file

@ -7,7 +7,6 @@ import sys
import socket
import platform
from appdirs import user_data_dir
from twisted.web import server
from twisted.internet import reactor, defer
from jsonrpc.proxy import JSONRPCProxy
@ -15,22 +14,10 @@ from jsonrpc.proxy import JSONRPCProxy
from lbrynet.lbrynet_daemon.LBRYDaemonServer import LBRYDaemonServer
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_ADDRESS, API_PORT, \
DEFAULT_WALLET, UI_ADDRESS, DEFAULT_UI_BRANCH
from lbrynet import LOG_PATH
if sys.platform != "darwin":
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
else:
log_dir = user_data_dir("LBRY")
if not os.path.isdir(log_dir):
os.mkdir(log_dir)
LOG_FILENAME = os.path.join(log_dir, 'lbrynet-daemon.log')
log = logging.getLogger(__name__)
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5)
log.addHandler(handler)
log.setLevel(logging.INFO)
log = logging.getLogger(LOG_PATH)
REMOTE_SERVER = "www.google.com"
@ -96,7 +83,7 @@ def start():
if not args.logtoconsole and not args.quiet:
print "Starting lbrynet-daemon from command line"
print "To view activity, view the log file here: " + LOG_FILENAME
print "To view activity, view the log file here: " + LOG_PATH
print "Web UI is available at http://%s:%i" % (API_INTERFACE, API_PORT)
print "JSONRPC API is available at " + API_CONNECTION_STRING
print "To quit press ctrl-c or call 'stop' via the API"

View file

@ -5,15 +5,10 @@ import json
import sys
import mimetypes
from StringIO import StringIO
from zipfile import ZipFile
from urllib import urlopen
from datetime import datetime
from appdirs import user_data_dir
from twisted.web import server, static, resource
from twisted.internet import defer, interfaces, error, reactor, task, threads
from twisted.python.failure import Failure
from txjsonrpc.web import jsonrpc
from zope.interface import implements
@ -25,19 +20,10 @@ if sys.platform != "darwin":
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
else:
data_dir = user_data_dir("LBRY")
if not os.path.isdir(data_dir):
os.mkdir(data_dir)
version_dir = os.path.join(data_dir, "ui_version_history")
if not os.path.isdir(version_dir):
os.mkdir(version_dir)
version_log = logging.getLogger("lbry_version")
version_log.addHandler(logging.FileHandler(os.path.join(version_dir, "lbry_version.log")))
version_log.setLevel(logging.INFO)
log = logging.getLogger(__name__)
log.addHandler(logging.FileHandler(os.path.join(data_dir, 'lbrynet-daemon.log')))
log.setLevel(logging.INFO)
class LBRYindex(resource.Resource):

View file

@ -27,19 +27,7 @@ STREAM_STAGES = [
(DOWNLOAD_TIMEOUT_CODE, 'Stream timed out')
]
if sys.platform != "darwin":
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
else:
log_dir = user_data_dir("LBRY")
if not os.path.isdir(log_dir):
os.mkdir(log_dir)
LOG_FILENAME = os.path.join(log_dir, 'lbrynet-daemon.log')
log = logging.getLogger(__name__)
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5)
log.addHandler(handler)
log.setLevel(logging.INFO)
class GetStream(object):

View file

@ -12,19 +12,7 @@ from lbrynet.core.PaymentRateManager import PaymentRateManager
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloader
from twisted.internet import threads, defer
if sys.platform != "darwin":
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
else:
log_dir = user_data_dir("LBRY")
if not os.path.isdir(log_dir):
os.mkdir(log_dir)
LOG_FILENAME = os.path.join(log_dir, 'lbrynet-daemon.log')
log = logging.getLogger(__name__)
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5)
log.addHandler(handler)
log.setLevel(logging.INFO)
class Publisher(object):

View file

@ -14,20 +14,7 @@ from lbryum.version import ELECTRUM_VERSION as lbryum_version
from zipfile import ZipFile
from appdirs import user_data_dir
if sys.platform != "darwin":
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
else:
data_dir = user_data_dir("LBRY")
if not os.path.isdir(data_dir):
os.mkdir(data_dir)
version_dir = os.path.join(data_dir, "ui_version_history")
if not os.path.isdir(version_dir):
os.mkdir(version_dir)
log = logging.getLogger(__name__)
log.addHandler(logging.FileHandler(os.path.join(data_dir, 'lbrynet-daemon.log')))
log.setLevel(logging.INFO)
class LBRYUIManager(object):

View file

@ -0,0 +1,4 @@
import logging
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)