diff --git a/.bzrignore b/.bzrignore index 7ae985ce4df..b83a43bf1d4 100644 --- a/.bzrignore +++ b/.bzrignore @@ -9,4 +9,3 @@ RE:^include/ RE:^share/ RE:^man/ RE:^lib/ -logging.cfg diff --git a/logging.json b/logging.json new file mode 100644 index 00000000000..36b2952a6ec --- /dev/null +++ b/logging.json @@ -0,0 +1,27 @@ +{ + "version": 1, + "formatters": { + "simple": { + "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s" + } + }, + "handlers": { + "console": { + "class": "logging.StreamHandler", + "level": "DEBUG", + "formatter": "simple", + "stream": "ext://sys.stdout" + } + }, + "loggers": { + "web": { + }, + "web.common.openerplib": { + "level": "INFO" + } + }, + "root": { + "level": "DEBUG", + "handlers": ["console"] + } +} diff --git a/openerp-web.py b/openerp-web.py index 928a62e4528..e167568cdab 100755 --- a/openerp-web.py +++ b/openerp-web.py @@ -2,6 +2,7 @@ import optparse import os import sys +import json import tempfile import logging import logging.config @@ -48,7 +49,7 @@ logging_opts = optparse.OptionGroup(optparser, "Logging") logging_opts.add_option("--log-level", dest="log_level", type="choice", default='debug', help="Global logging level", metavar="LOG_LEVEL", choices=['debug', 'info', 'warning', 'error', 'critical']) -logging_opts.add_option("--log-config", dest="log_config", +logging_opts.add_option("--log-config", dest="log_config", default=os.path.join(os.path.dirname(__file__), "logging.json"), help="Logging configuration file", metavar="FILE") optparser.add_option_group(logging_opts) @@ -60,10 +61,13 @@ if __name__ == "__main__": os.environ["TZ"] = "UTC" - if not options.log_config: - logging.basicConfig(level=getattr(logging, options.log_level.upper())) + if sys.version_info >= (2, 7): + with open(options.log_config) as file: + dct = json.load(file) + logging.config.dictConfig(dct) + logging.getLogger("").setLevel(getattr(logging, options.log_level.upper())) else: - logging.config.fileConfig(options.log_config) + logging.basicConfig(level=getattr(logging, options.log_level.upper())) app = web.common.dispatch.Root(options)