Fixed undesirable log_level replacement in depends
This commit is contained in:
parent
40a14748be
commit
a1a8d3a05d
|
@ -2581,7 +2581,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
os.remove(state.appdata + 'knownnodes.dat')
|
||||
previousAppdataLocation = state.appdata
|
||||
state.appdata = paths.lookupExeFolder()
|
||||
debug.restartLoggingInUpdatedAppdataLocation()
|
||||
debug.resetLogging()
|
||||
try:
|
||||
os.remove(previousAppdataLocation + 'debug.log')
|
||||
os.remove(previousAppdataLocation + 'debug.log.1')
|
||||
|
@ -2599,7 +2599,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
knownnodes.saveKnownNodes(state.appdata)
|
||||
os.remove(paths.lookupExeFolder() + 'keys.dat')
|
||||
os.remove(paths.lookupExeFolder() + 'knownnodes.dat')
|
||||
debug.restartLoggingInUpdatedAppdataLocation()
|
||||
debug.resetLogging()
|
||||
try:
|
||||
os.remove(paths.lookupExeFolder() + 'debug.log')
|
||||
os.remove(paths.lookupExeFolder() + 'debug.log.1')
|
||||
|
|
47
src/debug.py
47
src/debug.py
|
@ -23,6 +23,7 @@ Use: `from debug import logger` to import this facility into whatever module you
|
|||
|
||||
"""
|
||||
|
||||
import ConfigParser
|
||||
import logging
|
||||
import logging.config
|
||||
import os
|
||||
|
@ -44,28 +45,26 @@ def log_uncaught_exceptions(ex_cls, ex, tb):
|
|||
|
||||
|
||||
def configureLogging():
|
||||
have_logging = False
|
||||
fail_msg = ''
|
||||
try:
|
||||
logging.config.fileConfig(os.path.join(state.appdata, 'logging.dat'))
|
||||
have_logging = True
|
||||
print(
|
||||
'Loaded logger configuration from %s' %
|
||||
os.path.join(state.appdata, 'logging.dat'))
|
||||
except:
|
||||
if os.path.isfile(os.path.join(state.appdata, 'logging.dat')):
|
||||
print(
|
||||
'Failed to load logger configuration from %s, using default'
|
||||
' logging config\n%s' %
|
||||
(os.path.join(state.appdata, 'logging.dat'), sys.exc_info()))
|
||||
logging_config = os.path.join(state.appdata, 'logging.dat')
|
||||
logging.config.fileConfig(logging_config)
|
||||
return (
|
||||
False,
|
||||
'Loaded logger configuration from %s' % logging_config
|
||||
)
|
||||
except (OSError, ConfigParser.NoSectionError):
|
||||
if os.path.isfile(logging_config):
|
||||
fail_msg = \
|
||||
'Failed to load logger configuration from %s, using default' \
|
||||
' logging config\n%s' % \
|
||||
(logging_config, sys.exc_info())
|
||||
else:
|
||||
# no need to confuse the user if the logger config is missing entirely
|
||||
print "Using default logger configuration"
|
||||
fail_msg = 'Using default logger configuration'
|
||||
|
||||
sys.excepthook = log_uncaught_exceptions
|
||||
|
||||
if have_logging:
|
||||
return False
|
||||
|
||||
logging.config.dictConfig({
|
||||
'version': 1,
|
||||
'formatters': {
|
||||
|
@ -84,7 +83,7 @@ def configureLogging():
|
|||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'formatter': 'default',
|
||||
'level': log_level,
|
||||
'filename': state.appdata + 'debug.log',
|
||||
'filename': os.path.join(state.appdata, 'debug.log'),
|
||||
'maxBytes': 2097152, # 2 MiB
|
||||
'backupCount': 1,
|
||||
'encoding': 'UTF-8',
|
||||
|
@ -109,26 +108,28 @@ def configureLogging():
|
|||
'handlers': ['console'],
|
||||
},
|
||||
})
|
||||
return True
|
||||
|
||||
return True, fail_msg
|
||||
|
||||
# TODO (xj9): Get from a config file.
|
||||
# logger = logging.getLogger('console_only')
|
||||
|
||||
def initLogging():
|
||||
if configureLogging():
|
||||
preconfigured, msg = configureLogging()
|
||||
if preconfigured:
|
||||
if '-c' in sys.argv:
|
||||
logger = logging.getLogger('file_only')
|
||||
else:
|
||||
logger = logging.getLogger('both')
|
||||
else:
|
||||
logger = logging.getLogger('default')
|
||||
|
||||
if msg:
|
||||
logger.log(logging.WARNING if preconfigured else logging.INFO, msg)
|
||||
return logger
|
||||
|
||||
|
||||
def restartLoggingInUpdatedAppdataLocation():
|
||||
def resetLogging():
|
||||
global logger
|
||||
for i in list(logger.handlers):
|
||||
for i in logger.handlers.iterkeys():
|
||||
logger.removeHandler(i)
|
||||
i.flush()
|
||||
i.close()
|
||||
|
|
|
@ -19,15 +19,14 @@ import os
|
|||
from importlib import import_module
|
||||
|
||||
# We can now use logging so set up a simple configuration
|
||||
formatter = logging.Formatter(
|
||||
'%(levelname)s: %(message)s'
|
||||
)
|
||||
formatter = logging.Formatter('%(levelname)s: %(message)s')
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
handler.setFormatter(formatter)
|
||||
logger = logging.getLogger('both')
|
||||
logger.addHandler(handler)
|
||||
logger.setLevel(logging.ERROR)
|
||||
|
||||
|
||||
OS_RELEASE = {
|
||||
"Debian GNU/Linux".lower(): "Debian",
|
||||
"fedora": "Fedora",
|
||||
|
@ -464,3 +463,6 @@ def check_dependencies(verbose=False, optional=False):
|
|||
'PyBitmessage cannot start. One or more dependencies are'
|
||||
' unavailable.'
|
||||
)
|
||||
|
||||
|
||||
logger.setLevel(0)
|
||||
|
|
|
@ -34,7 +34,7 @@ import os
|
|||
import socket
|
||||
import sys
|
||||
|
||||
import logging as logger
|
||||
from debug import logger
|
||||
import defaults
|
||||
import tr # translate
|
||||
from bmconfigparser import BMConfigParser
|
||||
|
|
Reference in New Issue
Block a user