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