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