Replace option "debug" with "level" in "logging"
This commit is contained in:
parent
a5fa35e785
commit
59f7104dce
5
config
5
config
@ -125,8 +125,9 @@
|
|||||||
|
|
||||||
[logging]
|
[logging]
|
||||||
|
|
||||||
# Set the logging level to debug
|
# Threshold for the logger
|
||||||
#debug = False
|
# Value: debug | info | warning | error | critical
|
||||||
|
#level = warning
|
||||||
|
|
||||||
# Don't include passwords in logs
|
# Don't include passwords in logs
|
||||||
#mask_passwords = True
|
#mask_passwords = True
|
||||||
|
@ -850,7 +850,7 @@ def _init_application(config_path, wsgi_errors):
|
|||||||
_application_config_path = config_path
|
_application_config_path = config_path
|
||||||
configuration = config.load([config_path] if config_path else [],
|
configuration = config.load([config_path] if config_path else [],
|
||||||
ignore_missing_paths=False)
|
ignore_missing_paths=False)
|
||||||
log.set_debug(configuration.getboolean("logging", "debug"))
|
log.set_level(configuration.get("logging", "level"))
|
||||||
_application = Application(configuration)
|
_application = Application(configuration)
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,6 +41,8 @@ def run():
|
|||||||
help="check the storage for errors and exit")
|
help="check the storage for errors and exit")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-C", "--config", help="use a specific configuration file")
|
"-C", "--config", help="use a specific configuration file")
|
||||||
|
parser.add_argument("-D", "--debug", action="store_true",
|
||||||
|
help="print debug information")
|
||||||
|
|
||||||
groups = {}
|
groups = {}
|
||||||
for section, values in config.INITIAL_CONFIG.items():
|
for section, values in config.INITIAL_CONFIG.items():
|
||||||
@ -76,7 +78,10 @@ def run():
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Preliminary configure logging
|
# Preliminary configure logging
|
||||||
log.set_debug(args.logging_debug)
|
if args.debug:
|
||||||
|
args.logging_level = "debug"
|
||||||
|
if args.logging_level is not None:
|
||||||
|
log.set_level(args.logging_level)
|
||||||
|
|
||||||
if args.config is not None:
|
if args.config is not None:
|
||||||
config_paths = [args.config] if args.config else []
|
config_paths = [args.config] if args.config else []
|
||||||
@ -103,7 +108,7 @@ def run():
|
|||||||
configuration.set(section, action.split('_', 1)[1], value)
|
configuration.set(section, action.split('_', 1)[1], value)
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
log.set_debug(configuration.getboolean("logging", "debug"))
|
log.set_level(configuration.get("logging", "level"))
|
||||||
|
|
||||||
if args.verify_storage:
|
if args.verify_storage:
|
||||||
logger.info("Verifying storage")
|
logger.info("Verifying storage")
|
||||||
|
@ -49,6 +49,12 @@ def positive_float(value):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def logging_level(value):
|
||||||
|
if value not in ("debug", "info", "warning", "error", "critical"):
|
||||||
|
raise ValueError("unsupported level: %s" % value)
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
# Default configuration
|
# Default configuration
|
||||||
INITIAL_CONFIG = OrderedDict([
|
INITIAL_CONFIG = OrderedDict([
|
||||||
("server", OrderedDict([
|
("server", OrderedDict([
|
||||||
@ -173,11 +179,10 @@ INITIAL_CONFIG = OrderedDict([
|
|||||||
"type": str,
|
"type": str,
|
||||||
"internal": web.INTERNAL_TYPES})])),
|
"internal": web.INTERNAL_TYPES})])),
|
||||||
("logging", OrderedDict([
|
("logging", OrderedDict([
|
||||||
("debug", {
|
("level", {
|
||||||
"value": "False",
|
"value": "warning",
|
||||||
"help": "print debug information",
|
"help": "threshold for the logger",
|
||||||
"aliases": ["-D", "--debug"],
|
"type": logging_level}),
|
||||||
"type": bool}),
|
|
||||||
("mask_passwords", {
|
("mask_passwords", {
|
||||||
"value": "True",
|
"value": "True",
|
||||||
"help": "mask passwords in logs",
|
"help": "mask passwords in logs",
|
||||||
|
@ -116,16 +116,16 @@ def setup():
|
|||||||
handler = ThreadStreamsHandler(sys.stderr, get_default_handler())
|
handler = ThreadStreamsHandler(sys.stderr, get_default_handler())
|
||||||
logging.basicConfig(format=LOGGER_FORMAT, handlers=[handler])
|
logging.basicConfig(format=LOGGER_FORMAT, handlers=[handler])
|
||||||
register_stream = handler.register_stream
|
register_stream = handler.register_stream
|
||||||
set_debug(True)
|
set_level(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
def set_debug(debug):
|
def set_level(level):
|
||||||
"""Set debug mode for global logger."""
|
"""Set logging level for global logger."""
|
||||||
if debug:
|
if isinstance(level, str):
|
||||||
root_logger.setLevel(logging.DEBUG)
|
level = getattr(logging, level.upper())
|
||||||
logger.setLevel(logging.DEBUG)
|
root_logger.setLevel(level)
|
||||||
|
logger.setLevel(level)
|
||||||
|
if level == logging.DEBUG:
|
||||||
logger.removeFilter(removeTracebackFilter)
|
logger.removeFilter(removeTracebackFilter)
|
||||||
else:
|
else:
|
||||||
root_logger.setLevel(logging.WARNING)
|
|
||||||
logger.setLevel(logging.WARNING)
|
|
||||||
logger.addFilter(removeTracebackFilter)
|
logger.addFilter(removeTracebackFilter)
|
||||||
|
Loading…
Reference in New Issue
Block a user