From 3441dd4d2d1ed771f241cd1a140bc7d2d2dfcd4c Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 7 Jun 2016 04:19:51 -0400 Subject: [PATCH] don't mess with logging --- lbrynet/__init__.py | 24 +-------------------- lbrynet/lbrynet_daemon/LBRYDaemon.py | 22 +++++++++++++++---- lbrynet/lbrynet_daemon/LBRYDaemonControl.py | 17 ++++++++++++--- lbrynet/lbrynet_daemon/LBRYDaemonServer.py | 6 +++++- lbrynet/lbrynet_daemon/LBRYDownloader.py | 15 +++++++++++-- lbrynet/lbrynet_daemon/LBRYPublisher.py | 13 +++++++++++ lbrynet/lbrynet_daemon/LBRYUIManager.py | 14 +++++++++++- lbrynet/lbrynet_daemon/__init__.py | 4 ---- 8 files changed, 77 insertions(+), 38 deletions(-) diff --git a/lbrynet/__init__.py b/lbrynet/__init__.py index 4882c1e23..7bb1777c8 100644 --- a/lbrynet/__init__.py +++ b/lbrynet/__init__.py @@ -1,29 +1,7 @@ import logging -import logging.handlers -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") - -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)) +logging.getLogger(__name__).addHandler(logging.NullHandler()) log.setLevel(logging.ERROR) version = (0, 2, 5) diff --git a/lbrynet/lbrynet_daemon/LBRYDaemon.py b/lbrynet/lbrynet_daemon/LBRYDaemon.py index e90343795..ac157bd71 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemon.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemon.py @@ -39,8 +39,7 @@ from lbrynet.lbrynet_daemon.LBRYPublisher import Publisher 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 + DEFAULT_WALLET, DEFAULT_SEARCH_TIMEOUT, DEFAULT_CACHE_TIME, DEFAULT_UI_BRANCH, LOG_POST_URL, LOG_FILE_NAME from lbrynet.conf import DEFAULT_TIMEOUT, WALLET_TYPES from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob from lbrynet.core.Session import LBRYSession @@ -49,10 +48,25 @@ from lbrynet.core.LBRYcrdWallet import LBRYcrdWallet, LBRYumWallet from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager from lbrynet.lbryfile.LBRYFileMetadataManager import DBLBRYFileMetadataManager, TempLBRYFileMetadataManager from lbryum import LOG_PATH as lbryum_log -from lbrynet import LOG_PATH as lbrynet_log log = logging.getLogger(__name__) + +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) + +lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME) + +log = logging.getLogger(__name__) +handler = logging.handlers.RotatingFileHandler(lbrynet_log, 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()) @@ -143,7 +157,7 @@ class LBRYDaemon(jsonrpc.JSONRPC): self.ip = None self.wallet_type = wallet_type self.first_run = None - self.log_file = LOG_PATH + self.log_file = lbrynet_log self.current_db_revision = 1 self.run_server = True self.session = None diff --git a/lbrynet/lbrynet_daemon/LBRYDaemonControl.py b/lbrynet/lbrynet_daemon/LBRYDaemonControl.py index 05134488a..8b4c95e41 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemonControl.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemonControl.py @@ -6,6 +6,7 @@ import webbrowser import sys import socket import platform +from appdirs import user_data_dir from twisted.web import server from twisted.internet import reactor, defer @@ -13,11 +14,21 @@ 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 + DEFAULT_WALLET, UI_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME +if sys.platform != "darwin": + log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet") +else: + log_dir = user_data_dir("LBRY") -log = logging.getLogger(LOG_PATH) +if not os.path.isdir(log_dir): + os.mkdir(log_dir) + +LOG_FILENAME = os.path.join(log_dir, LOG_FILE_NAME) +log = logging.getLogger(__name__) +handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5) +log.addHandler(handler) +log.setLevel(logging.INFO) REMOTE_SERVER = "www.google.com" diff --git a/lbrynet/lbrynet_daemon/LBRYDaemonServer.py b/lbrynet/lbrynet_daemon/LBRYDaemonServer.py index fd86887c9..ec5bebbc7 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemonServer.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemonServer.py @@ -13,7 +13,7 @@ from twisted.internet import defer, interfaces, error, reactor, task, threads from zope.interface import implements from lbrynet.lbrynet_daemon.LBRYDaemon import LBRYDaemon -from lbrynet.conf import API_CONNECTION_STRING, API_ADDRESS, DEFAULT_WALLET, UI_ADDRESS, DEFAULT_UI_BRANCH +from lbrynet.conf import API_CONNECTION_STRING, API_ADDRESS, DEFAULT_WALLET, UI_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME if sys.platform != "darwin": @@ -23,7 +23,11 @@ else: if not os.path.isdir(data_dir): os.mkdir(data_dir) +LOG_FILENAME = os.path.join(data_dir, LOG_FILE_NAME) log = logging.getLogger(__name__) +handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5) +log.addHandler(handler) +log.setLevel(logging.INFO) class LBRYindex(resource.Resource): diff --git a/lbrynet/lbrynet_daemon/LBRYDownloader.py b/lbrynet/lbrynet_daemon/LBRYDownloader.py index 47ec47cd7..6e3126958 100644 --- a/lbrynet/lbrynet_daemon/LBRYDownloader.py +++ b/lbrynet/lbrynet_daemon/LBRYDownloader.py @@ -12,7 +12,7 @@ from lbrynet.core.Error import InvalidStreamInfoError, InsufficientFundsError from lbrynet.core.PaymentRateManager import PaymentRateManager from lbrynet.core.StreamDescriptor import download_sd_blob from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloaderFactory -from lbrynet.conf import DEFAULT_TIMEOUT +from lbrynet.conf import DEFAULT_TIMEOUT, LOG_FILE_NAME INITIALIZING_CODE = 'initializing' DOWNLOAD_METADATA_CODE = 'downloading_metadata' @@ -27,8 +27,19 @@ STREAM_STAGES = [ (DOWNLOAD_TIMEOUT_CODE, 'Stream timed out') ] -log = logging.getLogger(__name__) +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, LOG_FILE_NAME) +log = logging.getLogger(__name__) +handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5) +log.addHandler(handler) +log.setLevel(logging.INFO) class GetStream(object): def __init__(self, sd_identifier, session, wallet, lbry_file_manager, max_key_fee, pay_key=True, data_rate=0.5, diff --git a/lbrynet/lbrynet_daemon/LBRYPublisher.py b/lbrynet/lbrynet_daemon/LBRYPublisher.py index 181dbe1bf..a2804aecb 100644 --- a/lbrynet/lbrynet_daemon/LBRYPublisher.py +++ b/lbrynet/lbrynet_daemon/LBRYPublisher.py @@ -10,9 +10,22 @@ from lbrynet.lbryfilemanager.LBRYFileCreator import create_lbry_file from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob from lbrynet.core.PaymentRateManager import PaymentRateManager from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloader +from lbrynet.conf import LOG_FILE_NAME 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, LOG_FILE_NAME) log = logging.getLogger(__name__) +handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5) +log.addHandler(handler) +log.setLevel(logging.INFO) class Publisher(object): diff --git a/lbrynet/lbrynet_daemon/LBRYUIManager.py b/lbrynet/lbrynet_daemon/LBRYUIManager.py index 425d31df4..76a75e284 100644 --- a/lbrynet/lbrynet_daemon/LBRYUIManager.py +++ b/lbrynet/lbrynet_daemon/LBRYUIManager.py @@ -8,13 +8,25 @@ from urllib2 import urlopen from StringIO import StringIO from twisted.web import static from twisted.internet import defer -from lbrynet.conf import DEFAULT_UI_BRANCH +from lbrynet.conf import DEFAULT_UI_BRANCH, LOG_FILE_NAME from lbrynet import __version__ as lbrynet_version from lbryum.version import ELECTRUM_VERSION as lbryum_version from zipfile import ZipFile 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") + +if not os.path.isdir(log_dir): + os.mkdir(log_dir) + +LOG_FILENAME = os.path.join(log_dir, LOG_FILE_NAME) log = logging.getLogger(__name__) +handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5) +log.addHandler(handler) +log.setLevel(logging.INFO) class LBRYUIManager(object): diff --git a/lbrynet/lbrynet_daemon/__init__.py b/lbrynet/lbrynet_daemon/__init__.py index 1a5ad27bc..e69de29bb 100644 --- a/lbrynet/lbrynet_daemon/__init__.py +++ b/lbrynet/lbrynet_daemon/__init__.py @@ -1,4 +0,0 @@ -import logging - -log = logging.getLogger(__name__) -log.setLevel(logging.INFO) \ No newline at end of file