From 8641826ca48b99a88eb9543fef0dcf287bd39814 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 10 Dec 2014 14:10:17 +0100 Subject: [PATCH] [IMP] config: make log_handler and --log-handler additive For log_handler (list of logger configuration specs), having the configuration file and the CLI configuration be exclusive (one overwriting the other) is detrimental: it precludes keeping the configuration file as a convenient baseline and only altering the subset of loggers of interest at any given time. Combine specs from both sources instead of overwriting one with the other. * remove log_handler and its special case from the first options loop * remove seeding of option with DEFAULT_LOG_HANDLER * my_default is the baseline "configuration file" value, it's None if not provided which is not convenient. Use DEFAULT_LOG_HANDLER for it as baseline configuration file. DEFAULT_LOG_HANDLER isn't a list anymore, it's a CSV of logger specs (same as file-serialized) * could actually use a DEFAULT_LOG_HANDLER of ``:`` (the default logger is root, the default level is info), but that might be a tad too cryptic * things are weird between my_default and the file-sourced value, _parse_config is first run with my_defaults then with the file, but if there's no file it's re-run with already-parsed my_defaults. So when the file and the command-line values are of different type, _parse_config must be ready to handle both --- openerp/tools/config.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openerp/tools/config.py b/openerp/tools/config.py index 24e6b6b00f9..74770f2635d 100644 --- a/openerp/tools/config.py +++ b/openerp/tools/config.py @@ -58,7 +58,7 @@ def check_ssl(): except: return False -DEFAULT_LOG_HANDLER = [':INFO'] +DEFAULT_LOG_HANDLER = ':INFO' def _get_default_datadir(): home = os.path.expanduser('~') @@ -189,7 +189,7 @@ class configmanager(object): group.add_option("--logfile", dest="logfile", help="file where the server log will be stored") group.add_option("--logrotate", dest="logrotate", action="store_true", my_default=False, help="enable logfile rotation") group.add_option("--syslog", action="store_true", dest="syslog", my_default=False, help="Send the log to the syslog server") - group.add_option('--log-handler', action="append", default=list(DEFAULT_LOG_HANDLER), my_default=list(DEFAULT_LOG_HANDLER), metavar="PREFIX:LEVEL", help='setup a handler at LEVEL for a given PREFIX. An empty PREFIX indicates the root logger. This option can be repeated. Example: "openerp.orm:DEBUG" or "werkzeug:CRITICAL" (default: ":INFO")') + group.add_option('--log-handler', action="append", default=[], my_default=DEFAULT_LOG_HANDLER, metavar="PREFIX:LEVEL", help='setup a handler at LEVEL for a given PREFIX. An empty PREFIX indicates the root logger. This option can be repeated. Example: "openerp.orm:DEBUG" or "werkzeug:CRITICAL" (default: ":INFO")') group.add_option('--log-request', action="append_const", dest="log_handler", const="openerp.http.rpc.request:DEBUG", help='shortcut for --log-handler=openerp.http.rpc.request:DEBUG') group.add_option('--log-response', action="append_const", dest="log_handler", const="openerp.http.rpc.response:DEBUG", help='shortcut for --log-handler=openerp.http.rpc.response:DEBUG') group.add_option('--log-web', action="append_const", dest="log_handler", const="openerp.http:DEBUG", help='shortcut for --log-handler=openerp.http:DEBUG') @@ -402,14 +402,14 @@ class configmanager(object): 'db_maxconn', 'import_partial', 'addons_path', 'xmlrpc', 'syslog', 'without_demo', 'timezone', 'xmlrpcs_interface', 'xmlrpcs_port', 'xmlrpcs', - 'secure_cert_file', 'secure_pkey_file', 'dbfilter', 'log_handler', 'log_level', 'log_db', + 'secure_cert_file', 'secure_pkey_file', 'dbfilter', 'log_level', 'log_db', 'geoip_database', ] for arg in keys: # Copy the command-line argument (except the special case for log_handler, due to # action=append requiring a real default, so we cannot use the my_default workaround) - if getattr(opt, arg) and getattr(opt, arg) != DEFAULT_LOG_HANDLER: + if getattr(opt, arg): self.options[arg] = getattr(opt, arg) # ... or keep, but cast, the config file value. elif isinstance(self.options[arg], basestring) and self.casts[arg].type in optparse.Option.TYPE_CHECKER: @@ -417,6 +417,7 @@ class configmanager(object): if isinstance(self.options['log_handler'], basestring): self.options['log_handler'] = self.options['log_handler'].split(',') + self.options['log_handler'].extend(opt.log_handler) # if defined but None take the configfile value keys = [