From b54893f97bdef42cd7b9e5c8fa4dd080c13d64bd Mon Sep 17 00:00:00 2001 From: grakiss Date: Thu, 12 Oct 2017 05:34:50 -0400 Subject: [web-cvp]add a api to fecth logs of backend api JIRA: DOVETAIL-525 provide a easy way to fetch logs of backend apis Change-Id: I72054a6e155e6970254ed391dfa8b25943eceb35 Signed-off-by: grakiss --- cvp/docker/Dockerfile | 1 + cvp/docker/nginx/sites-enabled/default | 8 ++++++++ cvp/etc/config.ini | 1 + cvp/opnfv_testapi/cmd/server.py | 7 +++++++ 4 files changed, 17 insertions(+) diff --git a/cvp/docker/Dockerfile b/cvp/docker/Dockerfile index e0cb32fe..d0a34f37 100644 --- a/cvp/docker/Dockerfile +++ b/cvp/docker/Dockerfile @@ -59,6 +59,7 @@ WORKDIR /home/dovetail RUN git checkout -f $BRANCH RUN mkdir -p /home/testapi +RUN mkdir -p /home/testapi/logs/api RUN cp -rf /home/dovetail/cvp/* /home/testapi WORKDIR /home/dovetail/cvp diff --git a/cvp/docker/nginx/sites-enabled/default b/cvp/docker/nginx/sites-enabled/default index 5e152dd8..b6b6a7ed 100644 --- a/cvp/docker/nginx/sites-enabled/default +++ b/cvp/docker/nginx/sites-enabled/default @@ -57,6 +57,14 @@ server { autoindex_localtime on; } + location ~* /logs/api { + root /home/testapi; + expires 1d; + autoindex on; + autoindex_exact_size on; + autoindex_localtime on; + } + location /api/v1/cvp { proxy_pass http://cvpapi/api/v1/cvp; proxy_set_header X-Real-IP $remote_addr; diff --git a/cvp/etc/config.ini b/cvp/etc/config.ini index 92908f81..2cf08cc9 100644 --- a/cvp/etc/config.ini +++ b/cvp/etc/config.ini @@ -10,6 +10,7 @@ dbname = test_results_collection # Listening port url = http://localhost:8000/api/v1 port = 8011 +log_file = /home/testapi/logs/api/api.log # Number of results for one page (integer value) results_per_page = 20 diff --git a/cvp/opnfv_testapi/cmd/server.py b/cvp/opnfv_testapi/cmd/server.py index a5ac5eb6..d503c8a1 100644 --- a/cvp/opnfv_testapi/cmd/server.py +++ b/cvp/opnfv_testapi/cmd/server.py @@ -30,11 +30,18 @@ TODOs : """ import tornado.ioloop +import logging from opnfv_testapi.common.config import CONF from opnfv_testapi.router import url_mappings from opnfv_testapi.tornado_swagger import swagger +my_logger = logging.getLogger() +handler = logging.handlers.RotatingFileHandler( + CONF.api_log_file, maxBytes=20000000, backupCount=50) +my_logger.setLevel(logging.DEBUG) +my_logger.addHandler(handler) + def make_app(): swagger.docs(base_url=CONF.swagger_base_url, -- cgit 1.2.3-korg