Merge "Add log options to [DEFAULT] group in conf"
This commit is contained in:
commit
9f063dab02
@ -40,15 +40,14 @@ def setup_app():
|
|||||||
TEN_KB = 10 * 1024
|
TEN_KB = 10 * 1024
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
if os.path.isfile(CONF.api.log_file) and os.access(CONF.api.log_file,
|
if os.path.isfile(CONF.log_file) and os.access(CONF.log_file, os.W_OK):
|
||||||
os.W_OK):
|
|
||||||
handler = logging.handlers.RotatingFileHandler(
|
handler = logging.handlers.RotatingFileHandler(
|
||||||
CONF.api.log_file, maxBytes=TEN_KB, backupCount=1)
|
CONF.api.log_file, maxBytes=TEN_KB, backupCount=1)
|
||||||
handler.setLevel(log_level_map.get(CONF.api.log_level))
|
handler.setLevel(log_level_map.get(CONF.log_level))
|
||||||
formatter = logging.Formatter(CONF.api.log_format)
|
formatter = logging.Formatter(CONF.log_format)
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
app.logger.addHandler(handler)
|
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
|
@app.before_request
|
||||||
def before_request_logging():
|
def before_request_logging():
|
||||||
|
@ -47,7 +47,9 @@ def main():
|
|||||||
'bind': '%s:%s' % (CONF.api.bind_host, CONF.api.bind_port),
|
'bind': '%s:%s' % (CONF.api.bind_host, CONF.api.bind_port),
|
||||||
'reload': CONF.api.debug,
|
'reload': CONF.api.debug,
|
||||||
'timeout': CONF.api.timeout,
|
'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"),
|
LOG.info(("Valence Server on http://%(host)s:%(port)s"),
|
||||||
{'host': CONF.api.bind_host, 'port': CONF.api.bind_port})
|
{'host': CONF.api.bind_host, 'port': CONF.api.bind_port})
|
||||||
|
@ -15,12 +15,14 @@
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from valence.conf import api
|
from valence.conf import api
|
||||||
|
from valence.conf import default
|
||||||
from valence.conf import etcd
|
from valence.conf import etcd
|
||||||
from valence.conf import ironic_client
|
from valence.conf import ironic_client
|
||||||
from valence.conf import podm
|
from valence.conf import podm
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
default.register_opts(CONF)
|
||||||
api.register_opts(CONF)
|
api.register_opts(CONF)
|
||||||
etcd.register_opts(CONF)
|
etcd.register_opts(CONF)
|
||||||
ironic_client.register_opts(CONF)
|
ironic_client.register_opts(CONF)
|
||||||
|
@ -48,23 +48,21 @@ api_service_opts = [
|
|||||||
help=_('Configuration file for WSGI definition of API.')),
|
help=_('Configuration file for WSGI definition of API.')),
|
||||||
cfg.BoolOpt('debug',
|
cfg.BoolOpt('debug',
|
||||||
default=False,
|
default=False,
|
||||||
help=_('Enable debug mode for valence-api service.'))
|
help=_('Start API server in debug mode.'))
|
||||||
]
|
]
|
||||||
|
|
||||||
log_option = [
|
log_option = [
|
||||||
cfg.StrOpt('log_file',
|
cfg.StrOpt('log_file',
|
||||||
default='/var/log/valence/valence.log',
|
default='/var/log/valence/valence-api.log',
|
||||||
help=_('The log file location for valence-api service')),
|
help=_('The log file location for valence API server')),
|
||||||
cfg.StrOpt('log_level',
|
cfg.StrOpt('log_level',
|
||||||
default='debug',
|
default='info',
|
||||||
help=_('The granularity of Error log outputs.')),
|
choices=['info', 'critical', 'warning', 'debug', 'error'],
|
||||||
cfg.StrOpt('log_format',
|
help=_('The granularity of API server log outputs.')),
|
||||||
default='%(asctime)s %(name)-4s %(levelname)-4s %(message)s',
|
|
||||||
help=_('The log format.')),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
api_group = cfg.OptGroup(name='api',
|
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)
|
ALL_OPTS = (api_service_opts + log_option)
|
||||||
|
45
valence/conf/default.py
Normal file
45
valence/conf/default.py
Normal 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user