def __call__(self, func): if self.logger is None: LOG = logging.getLogger(func.__module__) self.logger = LOG.exception def call(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: with excutils.save_and_reraise_exception(): self.logger(e) return call
def log(method): """Decorator helping to log method calls.""" LOG = logging.getLogger(method.__module__) @functools.wraps(method) def wrapper(*args, **kwargs): instance = args[0] data = { "class_name": "%s.%s" % (instance.__class__.__module__, instance.__class__.__name__), "method_name": method.__name__, "args": args[1:], "kwargs": kwargs } LOG.debug( '%(class_name)s method %(method_name)s' ' called with arguments %(args)s %(kwargs)s', data) return method(*args, **kwargs) return wrapper
# 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 webob.dec from vnfsvc.api.views import versions as versions_view from vnfsvc.openstack.common import gettextutils from vnfsvc.openstack.common import log as logging from vnfsvc import wsgi LOG = logging.getLogger(__name__) class Versions(object): @classmethod def factory(cls, global_config, **local_config): return cls() @webob.dec.wsgify(RequestClass=wsgi.Request) def __call__(self, req): """Respond to a request for all Vnfsvc API versions.""" version_objs = [ { "id": "v1.0", "status": "CURRENT", },
# under the License. """Middleware that provides high-level error handling. It catches all exceptions from subsequent applications in WSGI pipeline to hide internal errors from API response. """ import webob.dec import webob.exc from vnfsvc.openstack.common.gettextutils import _ # noqa from vnfsvc.openstack.common import log as logging from vnfsvc.openstack.common.middleware import base LOG = logging.getLogger(__name__) class CatchErrorsMiddleware(base.Middleware): @webob.dec.wsgify def __call__(self, req): try: response = req.get_response(self.application) except Exception: LOG.exception(_('An error occurred during ' 'processing the request: %s')) response = webob.exc.HTTPInternalServerError() return response