Merge "Add log options to [DEFAULT] group in conf"

This commit is contained in:
Jenkins 2017-08-09 00:37:27 +00:00 committed by Gerrit Code Review
commit 9f063dab02
5 changed files with 61 additions and 15 deletions

View File

@ -40,15 +40,14 @@ def setup_app():
TEN_KB = 10 * 1024
# Configure logging
if os.path.isfile(CONF.api.log_file) and os.access(CONF.api.log_file,
os.W_OK):
if os.path.isfile(CONF.log_file) and os.access(CONF.log_file, os.W_OK):
handler = logging.handlers.RotatingFileHandler(
CONF.api.log_file, maxBytes=TEN_KB, backupCount=1)
handler.setLevel(log_level_map.get(CONF.api.log_level))
formatter = logging.Formatter(CONF.api.log_format)
handler.setLevel(log_level_map.get(CONF.log_level))
formatter = logging.Formatter(CONF.log_format)
handler.setFormatter(formatter)
app.logger.addHandler(handler)
app.logger.setLevel(log_level_map.get(CONF.api.log_level))
app.logger.setLevel(log_level_map.get(CONF.log_level))
@app.before_request
def before_request_logging():

View File

@ -47,7 +47,9 @@ def main():
'bind': '%s:%s' % (CONF.api.bind_host, CONF.api.bind_port),
'reload': CONF.api.debug,
'timeout': CONF.api.timeout,
'workers': CONF.api.workers
'workers': CONF.api.workers,
'loglevel': CONF.api.log_level,
'errorlog': CONF.api.log_file,
}
LOG.info(("Valence Server on http://%(host)s:%(port)s"),
{'host': CONF.api.bind_host, 'port': CONF.api.bind_port})

View File

@ -15,12 +15,14 @@
from oslo_config import cfg
from valence.conf import api
from valence.conf import default
from valence.conf import etcd
from valence.conf import ironic_client
from valence.conf import podm
CONF = cfg.CONF
default.register_opts(CONF)
api.register_opts(CONF)
etcd.register_opts(CONF)
ironic_client.register_opts(CONF)

View File

@ -48,23 +48,21 @@ api_service_opts = [
help=_('Configuration file for WSGI definition of API.')),
cfg.BoolOpt('debug',
default=False,
help=_('Enable debug mode for valence-api service.'))
help=_('Start API server in debug mode.'))
]
log_option = [
cfg.StrOpt('log_file',
default='/var/log/valence/valence.log',
help=_('The log file location for valence-api service')),
default='/var/log/valence/valence-api.log',
help=_('The log file location for valence API server')),
cfg.StrOpt('log_level',
default='debug',
help=_('The granularity of Error log outputs.')),
cfg.StrOpt('log_format',
default='%(asctime)s %(name)-4s %(levelname)-4s %(message)s',
help=_('The log format.')),
default='info',
choices=['info', 'critical', 'warning', 'debug', 'error'],
help=_('The granularity of API server log outputs.')),
]
api_group = cfg.OptGroup(name='api',
title='Options for the valence-api service')
title='Options for the valence API ')
ALL_OPTS = (api_service_opts + log_option)

45
valence/conf/default.py Normal file
View File

@ -0,0 +1,45 @@
# Copyright (c) 2017 Intel, Inc.
#
# 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.
from oslo_config import cfg
from valence.common.i18n import _
log_opts = [
cfg.StrOpt('log_file',
default='/var/log/valence/valence.log',
help=_('The log file location for valence service')),
cfg.StrOpt('log_level',
default='info',
choices=['info', 'critical', 'warning', 'debug', 'error',
'notset'],
help=_('The granularity of log outputs. By default set to '
'info level')),
cfg.StrOpt('log_format',
default='%(asctime)s %(name)-4s %(levelname)-4s %(message)s',
help=_('The log format.')),
]
ALL_OPTS = (log_opts)
def register_opts(conf):
conf.register_opts(ALL_OPTS)
def list_opts():
return {
'DEFAULT': ALL_OPTS
}