diff --git a/AUTHORS b/AUTHORS index 72dbc755..d0b1c2ec 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,2 +1,4 @@ Alan Meadows Felipe Monteiro +Felipe Monteiro +Scott Hussey diff --git a/ChangeLog b/ChangeLog index d788f3e4..76e6b01c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ CHANGES ======= +* Add oslo.log integration to Deckhand. * DECKHAND-10: Barbican initial integration * DECKHAND-2: Design core Deckhand API framework * Oslo config integration (#1) diff --git a/README.rst b/README.rst index 492d1fcf..72d8b22d 100644 --- a/README.rst +++ b/README.rst @@ -8,5 +8,6 @@ To run:: $ sudo pip install uwsgi $ virtualenv -p python3 /var/tmp/deckhand $ . /var/tmp/deckhand/bin/activate - $ sudo pip install . + $ pip install . + $ python setup.py install $ uwsgi --http :9000 -w deckhand.deckhand --callable deckhand --enable-threads -L diff --git a/deckhand/conf/config.py b/deckhand/conf/config.py index 25f2bdee..b3957028 100644 --- a/deckhand/conf/config.py +++ b/deckhand/conf/config.py @@ -51,18 +51,31 @@ barbican_opts = [ help='URL override for the Barbican API endpoint.'), ] +logging_group = cfg.OptGroup( + name='logging', + title='Logging Options', + help='Logging options for Deckhand.') + +logging_opts = [ + cfg.StrOpt('global_logger_name', + default='deckhand', + help='Logger name for the top-level logger.') +] + def register_opts(conf): conf.register_group(barbican_group) conf.register_opts(barbican_opts, group=barbican_group) - conf.register_group(keystone_auth_group) conf.register_opts(keystone_auth_opts, group=keystone_auth_group) + conf.register_group(logging_group) + conf.register_opts(logging_opts, group=logging_group) def list_opts(): - return {keystone_auth_group: keystone_auth_opts, - barbican_group: barbican_opts} + return {barbican_group: barbican_opts, + keystone_auth_group: keystone_auth_opts, + logging_group: logging_opts} register_opts(CONF) diff --git a/deckhand/control/api.py b/deckhand/control/api.py index a5ca0606..588a9add 100644 --- a/deckhand/control/api.py +++ b/deckhand/control/api.py @@ -15,16 +15,46 @@ import os import falcon +from oslo_config import cfg +from oslo_log import log as logging +from deckhand.conf import config from deckhand.control import base as api_base from deckhand.control import secrets +CONF = cfg.CONF + + +def __setup_logging(): + LOGGER_NAME = CONF.logging.global_logger_name + LOG = logging.getLogger(__name__, LOGGER_NAME) + + logging.register_options(CONF) + + current_path = os.path.dirname(os.path.realpath(__file__)) + root_path = os.path.abspath(os.path.join(current_path, os.pardir, + os.pardir)) + logging_cfg_path = "%s/etc/deckhand/logging.conf" % root_path + + # If logging conf is in place we need to set log_config_append. Only do so + # if the log path already exists. + if ((not hasattr(CONF, 'log_config_append') or + CONF.log_config_append is None) and + os.path.isfile(logging_cfg_path)): + CONF.log_config_append = logging_cfg_path + + logging.setup(CONF, LOGGER_NAME) + LOG.debug('Initiated Deckhand logging.') + def start_api(state_manager=None): - """Start the Deckhand API service. + """Main entry point for initializing the Deckhand API service. - Create routes for the v1.0 API. + Create routes for the v1.0 API and sets up logging. """ + config.register_opts(CONF) + __setup_logging() + control_api = falcon.API(request_type=api_base.DeckhandRequest) v1_0_routes = [ diff --git a/etc/deckhand/logging.conf b/etc/deckhand/logging.conf new file mode 100644 index 00000000..076a787a --- /dev/null +++ b/etc/deckhand/logging.conf @@ -0,0 +1,35 @@ +[loggers] +keys=root + +[handlers] +keys=file,devel,syslog + +[formatters] +keys=simple,tests + +[logger_root] +level=DEBUG +handlers=file + +[handler_file] +class=FileHandler +level=DEBUG +args=('deckhand.log', 'w+') +formatter=tests + +[handler_syslog] +class=handlers.SysLogHandler +level=ERROR +args = ('/dev/log', handlers.SysLogHandler.LOG_USER) + +[handler_devel] +class=StreamHandler +level=DEBUG +args=(sys.stdout,) +formatter=simple + +[formatter_tests] +class = oslo_log.formatters.ContextFormatter + +[formatter_simple] +format=%(asctime)s.%(msecs)03d %(process)d %(levelname)s: %(message)s diff --git a/etc/deckhand/logging.conf.sample b/etc/deckhand/logging.conf.sample new file mode 100644 index 00000000..076a787a --- /dev/null +++ b/etc/deckhand/logging.conf.sample @@ -0,0 +1,35 @@ +[loggers] +keys=root + +[handlers] +keys=file,devel,syslog + +[formatters] +keys=simple,tests + +[logger_root] +level=DEBUG +handlers=file + +[handler_file] +class=FileHandler +level=DEBUG +args=('deckhand.log', 'w+') +formatter=tests + +[handler_syslog] +class=handlers.SysLogHandler +level=ERROR +args = ('/dev/log', handlers.SysLogHandler.LOG_USER) + +[handler_devel] +class=StreamHandler +level=DEBUG +args=(sys.stdout,) +formatter=simple + +[formatter_tests] +class = oslo_log.formatters.ContextFormatter + +[formatter_simple] +format=%(asctime)s.%(msecs)03d %(process)d %(levelname)s: %(message)s diff --git a/requirements.txt b/requirements.txt index 294054b9..97850f1a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,13 @@ falcon==1.1.0 +pbr!=2.1.0,>=2.0.0 # Apache-2.0 +six>=1.9.0 # MIT +stevedore>=1.20.0 # Apache-2.0 keystoneauth1>=2.21.0 # Apache-2.0 oslo.config>=3.22.0 # Apache-2.0 oslo.context>=2.14.0 # Apache-2.0 oslo.log>=3.22.0 # Apache-2.0 oslo.serialization>=1.10.0 # Apache-2.0 +oslo.utils>=3.20.0 # Apache-2.0 +oslo.i18n!=3.15.2,>=2.1.0 # Apache-2.0 python-barbicanclient>=4.0.0 # Apache-2.0