mirror of
https://github.com/moparisthebest/SickRage
synced 2025-01-07 03:48:02 -05:00
Fixed sickragetv/sickrage-issues#109 - resolves logging issues related to new code added in via last updates.
This commit is contained in:
parent
3214f879ac
commit
466ced4c02
@ -561,7 +561,7 @@ def initialize(consoleLogging=True):
|
|||||||
fileLogging=False
|
fileLogging=False
|
||||||
|
|
||||||
# init logging
|
# init logging
|
||||||
logger.initLogging(consoleLogging=consoleLogging, fileLogging=fileLogging, debug=DEBUG)
|
logger.initLogging(consoleLogging=consoleLogging, fileLogging=fileLogging, debugLogging=DEBUG)
|
||||||
|
|
||||||
# github api
|
# github api
|
||||||
try:gh = Github().get_organization(GIT_ORG).get_repo(GIT_REPO)
|
try:gh = Github().get_organization(GIT_ORG).get_repo(GIT_REPO)
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
@ -27,8 +27,6 @@ import threading
|
|||||||
import sickbeard
|
import sickbeard
|
||||||
from sickbeard import classes
|
from sickbeard import classes
|
||||||
|
|
||||||
censoredItems = {}
|
|
||||||
|
|
||||||
# log levels
|
# log levels
|
||||||
ERROR = logging.ERROR
|
ERROR = logging.ERROR
|
||||||
WARNING = logging.WARNING
|
WARNING = logging.WARNING
|
||||||
@ -42,62 +40,89 @@ reverseNames = {u'ERROR': ERROR,
|
|||||||
u'DEBUG': DEBUG,
|
u'DEBUG': DEBUG,
|
||||||
u'DB': DB}
|
u'DB': DB}
|
||||||
|
|
||||||
# send logging to null
|
censoredItems = {}
|
||||||
|
|
||||||
|
class NullHandler(logging.Handler):
|
||||||
|
def emit(self, record):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NullFilter(logging.Filter):
|
class NullFilter(logging.Filter):
|
||||||
def filter(self, record):
|
def filter(self, record):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class CensorFilter(logging.Filter):
|
|
||||||
def filter(self, record):
|
|
||||||
for k, v in censoredItems.items():
|
|
||||||
if v and len(v) > 0 and v in record.msg:
|
|
||||||
record.msg = record.msg.replace(v, len(v) * '*')
|
|
||||||
return True
|
|
||||||
|
|
||||||
def initLogging(logFile=None, consoleLogging=False, fileLogging=False, debug=False):
|
class CensorLoggingAdapter(logging.LoggerAdapter):
|
||||||
# set logging filename
|
def process(self, msg, kwargs):
|
||||||
if not logFile:
|
for k, v in self.extra.items():
|
||||||
logFile = os.path.join(sickbeard.LOG_DIR, 'sickrage.log')
|
if v and len(v) > 0 and v in msg:
|
||||||
|
msg = msg.replace(v, len(v) * '*')
|
||||||
# Add a new logging level DB
|
return msg, kwargs
|
||||||
logging.addLevelName(DB, 'DB')
|
|
||||||
|
|
||||||
# sickrage logger
|
|
||||||
sr_log = logging.getLogger()
|
|
||||||
sr_log.setLevel(DB)
|
|
||||||
|
|
||||||
# tornado loggers
|
|
||||||
logging.getLogger("tornado.access").addFilter(NullFilter())
|
|
||||||
|
|
||||||
# console log handler
|
|
||||||
if consoleLogging:
|
|
||||||
console = logging.StreamHandler()
|
|
||||||
console.addFilter(CensorFilter())
|
|
||||||
console.setLevel(INFO if not debug else DEBUG)
|
|
||||||
console.setFormatter(logging.Formatter('%(asctime)s %(levelname)s::%(message)s', '%H:%M:%S'))
|
|
||||||
sr_log.addHandler(console)
|
|
||||||
|
|
||||||
# rotating log file handler
|
|
||||||
if fileLogging:
|
|
||||||
rfh = logging.handlers.RotatingFileHandler(logFile, maxBytes=1024 * 1024, backupCount=5, encoding='utf-8')
|
|
||||||
rfh.addFilter(CensorFilter())
|
|
||||||
rfh.setLevel(DEBUG)
|
|
||||||
rfh.setFormatter(logging.Formatter('%(asctime)s %(levelname)-8s %(message)s', '%Y-%m-%d %H:%M:%S'))
|
|
||||||
sr_log.addHandler(rfh)
|
|
||||||
|
|
||||||
|
|
||||||
def log(msg, level=INFO, *args, **kwargs):
|
class Logger(object):
|
||||||
meThread = threading.currentThread().getName()
|
def __init__(self):
|
||||||
message = meThread + u" :: " + msg
|
self.logger = CensorLoggingAdapter(logging.getLogger('sickrage'), censoredItems)
|
||||||
|
self.consoleLogging = False
|
||||||
|
self.fileLogging = False
|
||||||
|
self.debugLogging = False
|
||||||
|
self.logFile = None
|
||||||
|
|
||||||
logging.log(level, message, *args, **kwargs)
|
def initLogging(self, consoleLogging=False, fileLogging=False, debugLogging=False):
|
||||||
if level == ERROR:
|
# set logging filename
|
||||||
classes.ErrorViewer.add(classes.UIError(message))
|
if not self.logFile:
|
||||||
|
self.logFile = os.path.join(sickbeard.LOG_DIR, 'sickrage.log')
|
||||||
|
|
||||||
def log_error_and_exit(self, error_msg, *args, **kwargs):
|
# add a new logging level DB
|
||||||
log(error_msg, ERROR, *args, **kwargs)
|
logging.addLevelName(DB, 'DB')
|
||||||
|
|
||||||
|
# don't propergate to root logger
|
||||||
|
logging.getLogger('sickrage').propagate = False
|
||||||
|
|
||||||
|
# set minimum logging level allowed
|
||||||
|
logging.getLogger('sickrage').setLevel(DB)
|
||||||
|
|
||||||
|
# console log handler
|
||||||
|
if consoleLogging:
|
||||||
|
console = logging.StreamHandler()
|
||||||
|
console.setLevel(INFO if not debugLogging else DEBUG)
|
||||||
|
console.setFormatter(logging.Formatter('%(asctime)s %(levelname)s::%(message)s', '%H:%M:%S'))
|
||||||
|
logging.getLogger('sickrage').addHandler(console)
|
||||||
|
|
||||||
|
# rotating log file handler
|
||||||
|
if fileLogging:
|
||||||
|
rfh = logging.handlers.RotatingFileHandler(self.logFile, maxBytes=1024 * 1024, backupCount=5, encoding='utf-8')
|
||||||
|
rfh.setLevel(DEBUG)
|
||||||
|
rfh.setFormatter(logging.Formatter('%(asctime)s %(levelname)-8s %(message)s', '%Y-%m-%d %H:%M:%S'))
|
||||||
|
logging.getLogger('sickrage').addHandler(rfh)
|
||||||
|
|
||||||
|
def log(self, msg, level=INFO, *args, **kwargs):
|
||||||
|
meThread = threading.currentThread().getName()
|
||||||
|
message = meThread + u" :: " + msg
|
||||||
|
|
||||||
|
self.logger.log(level, message, *args, **kwargs)
|
||||||
|
if level == ERROR:
|
||||||
|
classes.ErrorViewer.add(classes.UIError(message))
|
||||||
|
|
||||||
|
def log_error_and_exit(self, error_msg, *args, **kwargs):
|
||||||
|
self.log(error_msg, ERROR, *args, **kwargs)
|
||||||
|
|
||||||
|
if not self.consoleLogging:
|
||||||
|
sys.exit(error_msg.encode(sickbeard.SYS_ENCODING, 'xmlcharrefreplace'))
|
||||||
|
else:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
class Wrapper(object):
|
||||||
|
instance = Logger()
|
||||||
|
|
||||||
|
def __init__(self, wrapped):
|
||||||
|
self.wrapped = wrapped
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
try:
|
||||||
|
return getattr(self.wrapped, name)
|
||||||
|
except AttributeError:
|
||||||
|
return getattr(self.instance, name)
|
||||||
|
|
||||||
|
_globals = sys.modules[__name__] = Wrapper(sys.modules[__name__])
|
||||||
|
|
||||||
if not self.consoleLogging:
|
|
||||||
sys.exit(error_msg.encode(sickbeard.SYS_ENCODING, 'xmlcharrefreplace'))
|
|
||||||
else:
|
|
||||||
sys.exit(1)
|
|
@ -54,7 +54,8 @@ FILEDIR = os.path.join(TESTDIR, SHOWNAME)
|
|||||||
FILEPATH = os.path.join(FILEDIR, FILENAME)
|
FILEPATH = os.path.join(FILEDIR, FILENAME)
|
||||||
SHOWDIR = os.path.join(TESTDIR, SHOWNAME + " final")
|
SHOWDIR = os.path.join(TESTDIR, SHOWNAME + " final")
|
||||||
|
|
||||||
sickbeard.logger.initLogging(os.path.join(os.path.join(TESTDIR, 'Logs'), 'test_sickbeard.log'))
|
sickbeard.logger.logFile = os.path.join(os.path.join(TESTDIR, 'Logs'), 'test_sickbeard.log')
|
||||||
|
sickbeard.logger.initLogging()
|
||||||
|
|
||||||
#=================
|
#=================
|
||||||
# prepare env functions
|
# prepare env functions
|
||||||
|
Loading…
Reference in New Issue
Block a user