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 08c66937..adc1af2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,8 @@ CHANGES ======= -* Implement core Deckhand API framework +* Add oslo.log integration to Deckhand. +* DECKHAND-2: Design core Deckhand API framework * Oslo config integration (#1) * Add ChangeLog * Initial commit diff --git a/README.rst b/README.rst index 2f709a99..72d8b22d 100644 --- a/README.rst +++ b/README.rst @@ -8,6 +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 55adbed5..69689ceb 100644 --- a/deckhand/conf/config.py +++ b/deckhand/conf/config.py @@ -23,11 +23,25 @@ Barbican options for allowing Deckhand to communicate with Barbican. barbican_opts = [] +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(logging_group) + conf.register_opts(logging_opts, group=logging_group) def list_opts(): - return {barbican_group: barbican_opts} + return {barbican_group: barbican_opts, + logging_group: logging_opts} 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 eb5f7f6e..f89d21bf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,14 @@ 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 oslo.config>=3.22.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 keystoneauth1>=2.21.0 # Apache-2.0