diff options
author | Satoshi Kobayashi <satoshi-k@stratosphere.co.jp> | 2013-10-21 17:03:29 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-10-23 12:10:52 +0900 |
commit | a4693e6f2c2ceadc2c15aababd695d727a9acc94 (patch) | |
tree | ad6814b548bbe7bbe166d930462ca756ec60d101 | |
parent | 89b2c6aaf16e8145d246e9c44ff757ecd4b8ef7b (diff) |
To specify a logging configuration file
Setup of logging from a configuration file.
Refer to the following for the details of a configuration file.
http://docs.python.org/2/library/logging.config.html
Signed-off-by: Satoshi Kobayashi <satoshi-k@stratosphere.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/log.py | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -14,12 +14,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function from oslo.config import cfg import inspect import logging +import logging.config import logging.handlers import os import sys +import ConfigParser CONF = cfg.CONF @@ -32,7 +35,9 @@ CONF.register_cli_opts([ cfg.StrOpt('log-dir', default=None, help='log file directory'), cfg.StrOpt('log-file', default=None, help='log file name'), cfg.StrOpt('log-file-mode', default='0644', - help='default log file permission') + help='default log file permission'), + cfg.StrOpt('log-config-file', default=None, + help='Path to a logging config file to use') ]) @@ -62,6 +67,17 @@ def init_log(): global _EARLY_LOG_HANDLER log = logging.getLogger() + + if CONF.log_config_file: + try: + logging.config.fileConfig(CONF.log_config_file, + disable_existing_loggers=True) + except ConfigParser.Error as e: + print('Failed to parse %s: %s' % (CONF.log_config_file, e), + file=sys.stderr) + sys.exit(2) + return + if CONF.use_stderr: log.addHandler(logging.StreamHandler(sys.stderr)) if _EARLY_LOG_HANDLER is not None: |