Add a configuration for the directory to generate gmr
If projects choose to have their own config parameter, they can use setup_autorun's log_dir parameter. if they want to let oslo.report's manage the configuration, they will have to call set_defaults and then use setup_autorun's conf parameter. Change-Id: I9ed0191628f2d552acd8130687b636671bc07a3e
This commit is contained in:
parent
57d6c1e34f
commit
c8980d92f4
35
oslo_reports/_i18n.py
Normal file
35
oslo_reports/_i18n.py
Normal file
@ -0,0 +1,35 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""oslo.i18n integration module.
|
||||
|
||||
See http://docs.openstack.org/developer/oslo.i18n/usage.html .
|
||||
|
||||
"""
|
||||
|
||||
import oslo_i18n
|
||||
|
||||
|
||||
_translators = oslo_i18n.TranslatorFactory(domain='oslo.reports')
|
||||
|
||||
# The primary translation function using the well-known name "_"
|
||||
_ = _translators.primary
|
||||
|
||||
# Translators for log levels.
|
||||
#
|
||||
# The abbreviated names are meant to reflect the usual use of a short
|
||||
# name like '_'. The "L" is for "log" and the other letter comes from
|
||||
# the level.
|
||||
_LI = _translators.log_info
|
||||
_LW = _translators.log_warning
|
||||
_LE = _translators.log_error
|
||||
_LC = _translators.log_critical
|
@ -23,16 +23,24 @@ For example, in a nova command module (under nova/cmd):
|
||||
.. code-block:: python
|
||||
:emphasize-lines: 8,9,10
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as oslo_logging
|
||||
from oslo_reports import opts as gmr_opts
|
||||
from oslo_reports import guru_meditation_report as gmr
|
||||
|
||||
CONF = cfg.CONF
|
||||
# maybe import some options here...
|
||||
|
||||
def main():
|
||||
config.parse_args(sys.argv)
|
||||
logging.setup('blah')
|
||||
oslo_logging.register_options(CONF)
|
||||
gmr_opts.set_defaults(CONF)
|
||||
|
||||
TextGuruMeditation.register_section('Some Special Section',
|
||||
CONF(sys.argv[1:], default_config_files=['myapp.conf'])
|
||||
oslo_logging.setup(CONF, 'myapp')
|
||||
|
||||
gmr.TextGuruMeditation.register_section('Some Special Section',
|
||||
special_section_generator)
|
||||
TextGuruMeditation.setup_autorun(version_object)
|
||||
gmr.TextGuruMeditation.setup_autorun(version_object, conf=CONF)
|
||||
|
||||
server = service.Service.create(binary='some-service',
|
||||
topic=CONF.some_service_topic)
|
||||
@ -106,7 +114,7 @@ class GuruMeditation(object):
|
||||
|
||||
@classmethod
|
||||
def setup_autorun(cls, version, service_name=None,
|
||||
log_dir=None, signum=None):
|
||||
log_dir=None, signum=None, conf=None):
|
||||
"""Set Up Auto-Run
|
||||
|
||||
This method sets up the Guru Meditation Report to automatically
|
||||
@ -117,6 +125,7 @@ class GuruMeditation(object):
|
||||
:param service_name: this program name used to construct logfile name
|
||||
:param logdir: path to a log directory where to create a file
|
||||
:param signum: the signal to associate with running the report
|
||||
:param conf: Configuration object, managed by the caller.
|
||||
"""
|
||||
|
||||
if not signum and hasattr(signal, 'SIGUSR1'):
|
||||
@ -124,6 +133,8 @@ class GuruMeditation(object):
|
||||
signum = signal.SIGUSR1
|
||||
|
||||
if signum:
|
||||
if log_dir is None and conf is not None:
|
||||
log_dir = conf.oslo_reports.log_dir
|
||||
signal.signal(signum,
|
||||
lambda sn, tb: cls.handle_signal(
|
||||
version, service_name, log_dir, tb))
|
||||
|
61
oslo_reports/opts.py
Normal file
61
oslo_reports/opts.py
Normal file
@ -0,0 +1,61 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
__all__ = [
|
||||
'list_opts',
|
||||
'set_defaults',
|
||||
]
|
||||
|
||||
import copy
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from oslo_reports._i18n import _
|
||||
|
||||
|
||||
_option_group = 'oslo_reports'
|
||||
|
||||
_options = [
|
||||
cfg.StrOpt('log_dir',
|
||||
help=_('Path to a log directory where to create a file')),
|
||||
]
|
||||
|
||||
|
||||
def list_opts():
|
||||
"""Return a list of oslo.config options available in the library.
|
||||
|
||||
The returned list includes all oslo.config options which may be registered
|
||||
at runtime by the library.
|
||||
Each element of the list is a tuple. The first element is the name of the
|
||||
group under which the list of elements in the second element will be
|
||||
registered. A group name of None corresponds to the [DEFAULT] group in
|
||||
config files.
|
||||
This function is also discoverable via the 'oslo_messaging' entry point
|
||||
under the 'oslo.config.opts' namespace.
|
||||
The purpose of this is to allow tools like the Oslo sample config file
|
||||
generator to discover the options exposed to users by this library.
|
||||
|
||||
:returns: a list of (group_name, opts) tuples
|
||||
"""
|
||||
|
||||
return [(_option_group, copy.deepcopy(_options))]
|
||||
|
||||
|
||||
def set_defaults(conf):
|
||||
"""Set defaults for configuration variables.
|
||||
|
||||
Overrides default options values.
|
||||
|
||||
:param conf: Configuration object, managed by the caller.
|
||||
:type conf: oslo.config.cfg.ConfigOpts
|
||||
"""
|
||||
conf.register_opts(_options, group=_option_group)
|
Loading…
Reference in New Issue
Block a user