diff --git a/deepaas/api/__init__.py b/deepaas/api/__init__.py index 3c45713e..fb8e66b9 100644 --- a/deepaas/api/__init__.py +++ b/deepaas/api/__init__.py @@ -18,14 +18,14 @@ from aiohttp import web import aiohttp_apispec from oslo_config import cfg -from oslo_log import log as logging import deepaas from deepaas.api import v2 from deepaas.api import versions +from deepaas import log from deepaas import model -LOG = logging.getLogger(__name__) +LOG = log.getLogger(__name__) APP = None diff --git a/deepaas/api/v2/__init__.py b/deepaas/api/v2/__init__.py index 3c626f8c..8064681c 100644 --- a/deepaas/api/v2/__init__.py +++ b/deepaas/api/v2/__init__.py @@ -17,13 +17,13 @@ from aiohttp import web import aiohttp_apispec from oslo_config import cfg -from oslo_log import log from deepaas.api.v2 import debug as v2_debug from deepaas.api.v2 import models as v2_model from deepaas.api.v2 import predict as v2_predict from deepaas.api.v2 import responses from deepaas.api.v2 import train as v2_train +from deepaas import log CONF = cfg.CONF LOG = log.getLogger("deepaas.api.v2") diff --git a/deepaas/api/v2/debug.py b/deepaas/api/v2/debug.py index c018b105..e380c04d 100644 --- a/deepaas/api/v2/debug.py +++ b/deepaas/api/v2/debug.py @@ -23,7 +23,8 @@ from aiohttp import web import aiohttp_apispec from oslo_config import cfg -from oslo_log import log + +from deepaas import log CONF = cfg.CONF diff --git a/deepaas/api/v2/train.py b/deepaas/api/v2/train.py index ca709c60..f5c278ae 100644 --- a/deepaas/api/v2/train.py +++ b/deepaas/api/v2/train.py @@ -21,12 +21,12 @@ from aiohttp import web import aiohttp_apispec -from oslo_log import log from webargs import aiohttpparser import webargs.core from deepaas.api.v2 import responses from deepaas.api.v2 import utils +from deepaas import log from deepaas import model LOG = log.getLogger("deepaas.api.v2.train") diff --git a/deepaas/cmd/cli.py b/deepaas/cmd/cli.py index 895a40b2..27baed9c 100644 --- a/deepaas/cmd/cli.py +++ b/deepaas/cmd/cli.py @@ -31,9 +31,9 @@ from datetime import datetime from marshmallow import fields from oslo_config import cfg -from oslo_log import log from deepaas import config +from deepaas import log from deepaas.model import loading from deepaas.model.v2 import wrapper as v2_wrapper @@ -247,7 +247,7 @@ def _add_methods(subparsers): CONF = cfg.CONF CONF.register_cli_opts(cli_opts) -LOG = log.getLogger(__name__) +LOG = log.get_logger(__name__) # store DEEPAAS_METHOD output in a file @@ -273,14 +273,16 @@ def main(): """Executes model's methods with corresponding parameters""" # we may add deepaas config, but then too many options... - # config.config_and_logging(sys.argv) + # config.setup(sys.argv) - log.register_options(CONF) - log.set_defaults(default_log_levels=log.get_default_log_levels()) + # FIXME(aloga): review this + # log.register_options(CONF) + # log.set_defaults(default_log_levels=log.get_default_log_levels()) CONF(sys.argv[1:], project="deepaas", version=deepaas.__version__) - log.setup(CONF, "deepaas-cli") + # FIXME(aloga): review this + # log.setup(CONF, "deepaas-cli") LOG.info("[INFO, Method] {} was called.".format(CONF.methods.name)) diff --git a/deepaas/cmd/run.py b/deepaas/cmd/run.py index 8f953d27..011ea3c0 100644 --- a/deepaas/cmd/run.py +++ b/deepaas/cmd/run.py @@ -19,10 +19,10 @@ from aiohttp import web from oslo_config import cfg -from oslo_log import log as oslo_log import deepaas from deepaas import api +import deepaas.log from deepaas.cmd import _shutdown from deepaas import config @@ -89,8 +89,8 @@ def main(): _shutdown.handle_signals() - config.config_and_logging(sys.argv) - log = oslo_log.getLogger("deepaas") + config.setup(sys.argv) + log = deepaas.log.LOG base = "http://{}:{}".format(CONF.listen_ip, CONF.listen_port) spec = "{}/swagger.json".format(base) diff --git a/deepaas/config.py b/deepaas/config.py index 0baafe97..385cede8 100644 --- a/deepaas/config.py +++ b/deepaas/config.py @@ -14,16 +14,14 @@ # License for the specific language governing permissions and limitations # under the License. -import logging import os import warnings from oslo_config import cfg -from oslo_log import log import deepaas +from deepaas import log -logging.captureWarnings(True) warnings.simplefilter("default", DeprecationWarning) opts = [ @@ -94,6 +92,30 @@ help=""" Specify the model to be used. If not specified, DEEPaaS will fail if there are more than only one models available. +""", + ), + cfg.BoolOpt( + "debug", + default=False, + help=""" +Enable debug mode in logging. This will provide more information about what +is happening in the API. Default is to not provide this information. +""", + ), + cfg.StrOpt( + "log-level", + default="INFO", + choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], + help=""" +Specify the log level for the API. Default is INFO. Possible values are DEBUG, +INFO, WARNING, ERROR, CRITICAL. +""", + ), + cfg.StrOpt( + "log-file", + default="", + help=""" +Specify the log file to use. If not specified, logs will be sent to stdout. """, ), ] @@ -102,11 +124,6 @@ CONF.register_cli_opts(opts) -def prepare_logging(): - log.register_options(cfg.CONF) - log.set_defaults(default_log_levels=log.get_default_log_levels()) - - def parse_args(argv, default_config_files=None): cfg.CONF( argv[1:], @@ -116,7 +133,9 @@ def parse_args(argv, default_config_files=None): ) -def config_and_logging(argv, default_config_files=None): - prepare_logging() +def setup(argv, default_config_files=None): parse_args(argv, default_config_files=default_config_files) - log.setup(cfg.CONF, "deepaas") + + log_level = (CONF.debug and "DEBUG") or CONF.log_level + + log.setup(log_level, CONF.log_file) diff --git a/deepaas/log.py b/deepaas/log.py new file mode 100644 index 00000000..a5d5a86e --- /dev/null +++ b/deepaas/log.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Spanish National Research Council (CSIC) +# +# 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. + +import logging + +logging.captureWarnings(True) + +LOG = logging.getLogger("deepaas") + + +log_format = ( + "%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [-] " + "%(message)s" +) +log_format_debug_suffix = "%(funcName)s %(pathname)s:%(lineno)d" + + +def getLogger(name): # noqa + return LOG.getChild(name) + + +def setup(log_level, log_file=None): + LOG.setLevel(log_level) + + if log_level == "DEBUG": + format_ = log_format + " [-] " + log_format_debug_suffix + else: + format_ = log_format + + logging.basicConfig(level=log_level, format=format_) + + if log_file: + fh = logging.FileHandler(log_file) + fh.setLevel(log_level) + LOG.addHandler(fh) + else: + ch = logging.StreamHandler() + ch.setLevel(log_level) + LOG.addHandler(ch) diff --git a/deepaas/model/v2/__init__.py b/deepaas/model/v2/__init__.py index 26aba281..e6e9b88b 100644 --- a/deepaas/model/v2/__init__.py +++ b/deepaas/model/v2/__init__.py @@ -14,10 +14,9 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_log import log - from deepaas import config from deepaas import exceptions +from deepaas import log from deepaas.model import loading from deepaas.model.v2 import wrapper diff --git a/deepaas/model/v2/wrapper.py b/deepaas/model/v2/wrapper.py index 156a711c..196abd8b 100644 --- a/deepaas/model/v2/wrapper.py +++ b/deepaas/model/v2/wrapper.py @@ -28,9 +28,9 @@ from aiohttp import web import marshmallow - from oslo_config import cfg -from oslo_log import log + +from deepaas import log LOG = log.getLogger(__name__) diff --git a/deepaas/tests/base.py b/deepaas/tests/base.py index 47a42c48..c618fa90 100644 --- a/deepaas/tests/base.py +++ b/deepaas/tests/base.py @@ -21,11 +21,9 @@ import fixtures from oslo_config import cfg from oslo_config import fixture as config_fixture -from oslo_log import log as logging import testtools CONF = cfg.CONF -logging.register_options(CONF) _TRUE_VALUES = ("True", "true", "1", "yes") diff --git a/deepaas/tests/fake_v2_model.py b/deepaas/tests/fake_v2_model.py index d4121f9a..f9c4d7f5 100644 --- a/deepaas/tests/fake_v2_model.py +++ b/deepaas/tests/fake_v2_model.py @@ -17,10 +17,10 @@ import base64 import time -from oslo_log import log from webargs import fields from webargs import validate +from deepaas import log from deepaas.model.v2 import base LOG = log.getLogger(__name__) diff --git a/deepaas/tests/test_v2_api.py b/deepaas/tests/test_v2_api.py index b97a1948..7cac6fe9 100644 --- a/deepaas/tests/test_v2_api.py +++ b/deepaas/tests/test_v2_api.py @@ -19,7 +19,6 @@ from aiohttp import web from oslo_config import cfg -from oslo_log import log as logging import deepaas from deepaas.api import v2 @@ -31,7 +30,6 @@ from deepaas.tests import fake_responses CONF = cfg.CONF -logging.register_options(CONF) def test_loading_ok_with_missing_schema(): diff --git a/doc/source/cli/deepaas-cli.rst b/doc/source/cli/deepaas-cli.rst index b194e79f..9b5779f3 100644 --- a/doc/source/cli/deepaas-cli.rst +++ b/doc/source/cli/deepaas-cli.rst @@ -21,8 +21,6 @@ Description by a user file; ``--deepaas_with_multiprocessing`` is to activate multiprocessing support, default is True. - oslo_log package is used for logging information, which provides - additional options for the script. If several models are available for loading, one has to provide which one to load via DEEPAAS_V2_MODEL environment setting. diff --git a/doc/source/install/configuration/config.rst b/doc/source/install/configuration/config.rst index a1dc0b87..56124848 100644 --- a/doc/source/install/configuration/config.rst +++ b/doc/source/install/configuration/config.rst @@ -7,8 +7,3 @@ For a sample configuration file, refer to :doc:`sample`. .. show-options:: deepaas - -Logging options ---------------- -.. show-options:: - oslo.log diff --git a/etc/deepaas-config-generator.conf b/etc/deepaas-config-generator.conf index eb3077bc..570d9602 100644 --- a/etc/deepaas-config-generator.conf +++ b/etc/deepaas-config-generator.conf @@ -2,4 +2,3 @@ output_file = etc/deepaas.conf.sample wrap_width = 79 namespace = deepaas -namespace = oslo.log diff --git a/pyproject.toml b/pyproject.toml index 060ba29c..1d0d2fdd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,6 @@ deepaas = "deepaas.opts:list_opts" [tool.poetry.dependencies] python = "^3.10" -"oslo.log" = "^6.0.0" "oslo.config" = "^9.4.0" stevedore = "^5.2.0" aiohttp = "^3.9.5"