Enable AOP for ocata logging 51/35951/2
authorYun Huang <yun.huang@windriver.com>
Thu, 15 Mar 2018 14:15:37 +0000 (22:15 +0800)
committerYun Huang <yun.huang@windriver.com>
Thu, 15 Mar 2018 14:15:37 +0000 (22:15 +0800)
Change-Id: I8a616e99d4fba368b7bedb9fc4c40ba4ceb10445
Issue-ID: MULTICLOUD-177
Signed-off-by: Yun Huang <yun.huang@windriver.com>
ocata/assembly.xml
ocata/ocata/pub/__init__.py [new file with mode: 0644]
ocata/ocata/pub/config/__init__.py [new file with mode: 0644]
ocata/ocata/pub/config/config.py [new file with mode: 0644]
ocata/ocata/pub/config/log.yml [new file with mode: 0644]
ocata/ocata/settings.py
ocata/pom.xml
ocata/requirements.txt
ocata/tox.ini

index e934f9f..1c69acd 100644 (file)
@@ -31,6 +31,7 @@
                 <include>**/*.wsdl</include>
                 <include>**/*.xsd</include>
                 <include>**/*.bpel</include>
+                <include>**/*.yml</include>
             </includes>
         </fileSet>
         <fileSet>
diff --git a/ocata/ocata/pub/__init__.py b/ocata/ocata/pub/__init__.py
new file mode 100644 (file)
index 0000000..afa702d
--- /dev/null
@@ -0,0 +1,14 @@
+# Copyright (c) 2017-2018 Wind River Systems, 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.
+
diff --git a/ocata/ocata/pub/config/__init__.py b/ocata/ocata/pub/config/__init__.py
new file mode 100644 (file)
index 0000000..afa702d
--- /dev/null
@@ -0,0 +1,14 @@
+# Copyright (c) 2017-2018 Wind River Systems, 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.
+
diff --git a/ocata/ocata/pub/config/config.py b/ocata/ocata/pub/config/config.py
new file mode 100644 (file)
index 0000000..ae1ce9d
--- /dev/null
@@ -0,0 +1,13 @@
+# Copyright (c) 2017-2018 Wind River Systems, 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.
diff --git a/ocata/ocata/pub/config/log.yml b/ocata/ocata/pub/config/log.yml
new file mode 100644 (file)
index 0000000..224864d
--- /dev/null
@@ -0,0 +1,34 @@
+version: 1
+disable_existing_loggers: False
+
+loggers:
+    ocata:
+      handlers: [ocata_handler]
+      level: "DEBUG"
+      propagate: False
+    newton_base:
+      handlers': [ocata_handler]
+      level: "DEBUG"
+      propagate: False
+    common:
+      handlers: [ocata_handler]
+      level: "DEBUG"
+      propagate: False
+handlers:
+    ocata_handler:
+        level: "DEBUG"
+        class: "logging.handlers.RotatingFileHandler"
+        filename: "/var/log/onap/multicloud/openstack/ocata/ocata.log"
+        formatter: "mdcFormat"
+        maxBytes: 1024*1024*50
+        backupCount: 10
+formatters:
+    standard:
+        format: "%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s"
+    mdcFormat:
+        format: "%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:[%(mdc)s]: %(message)s"
+        mdcfmt: "{requestID}"
+        datefmt: "%Y-%m-%d %H:%M:%S"
+        (): onaplogging.mdcformatter.MDCFormatter
+
+
index 9f5711d..169d83e 100644 (file)
 import os
 import sys
 
+from logging import config
+from onaplogging import monkey
+monkey.patch_all()
+
 CACHE_EXPIRATION_TIME = 3600
 
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
@@ -77,46 +81,6 @@ TIME_ZONE = 'UTC'
 
 STATIC_URL = '/static/'
 
-LOGGING = {
-    'version': 1,
-    'disable_existing_loggers': True,
-    'formatters': {
-        'standard': {
-            'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s',
-        },
-    },
-    'filters': {
-    },
-    'handlers': {
-        'ocata_handler': {
-            'level': 'DEBUG',
-            'class': 'logging.handlers.RotatingFileHandler',
-            'filename': '/var/log/onap/multicloud/openstack/ocata/ocata.log',
-            'formatter': 'standard',
-            'maxBytes': 1024 * 1024 * 50,
-            'backupCount': 5,
-        },
-    },
-
-    'loggers': {
-        'ocata': {
-            'handlers': ['ocata_handler'],
-            'level': 'DEBUG',
-            'propagate': False
-        },
-        'newton_base': {
-            'handlers': ['ocata_handler'],
-            'level': 'DEBUG',
-            'propagate': False
-        },
-        'common': {
-            'handlers': ['ocata_handler'],
-            'level': 'DEBUG',
-            'propagate': False
-        },
-    }
-}
-
 CACHES = {
     'default': {
         'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
@@ -150,9 +114,14 @@ ROOT_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__fi
 OPENSTACK_VERSION = "ocata"
 MULTIVIM_VERSION = "multicloud-" + OPENSTACK_VERSION
 
+LOGGING_CONFIG = None
+# yaml configuration of logging
+LOGGING_FILE = os.path.join(BASE_DIR, 'ocata/pub/config/log.yml')
+config.yamlConfig(filepath=LOGGING_FILE, watchDog=True)
+
 if 'test' in sys.argv:
 
-    LOGGING['handlers']['ocata_handler']['filename'] = 'logs/ocata.log'
+    #LOGGING['handlers']['ocata_handler']['filename'] = 'logs/ocata.log'
 
     REST_FRAMEWORK = {}
     import platform
index aae5c5b..51d9a95 100644 (file)
     <packaging>pom</packaging>
     <name>multicloud/openstack/ocata</name>
     <description>multicloud for openstack ocata</description>
-    <dependencies>
-        <dependency>
-            <groupId>org.onap.multicloud.openstack</groupId>
-            <artifactId>multicloud-openstack-newton</artifactId>
-            <version>1.1.0</version>
-            <type>zip</type>
-        </dependency>
-    </dependencies>
     <properties>
         <encoding>UTF-8</encoding>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
index 841fe27..76a3c0b 100644 (file)
@@ -15,3 +15,6 @@ python-memcached
 coverage==4.2
 mock==2.0.0
 unittest_xml_reporting==1.12.0
+
+# for onap logging 
+onappylog>=1.0.5
index be63b80..2fb81e7 100644 (file)
@@ -1,5 +1,5 @@
 [tox]
-envlist = py27,py35,cov
+envlist = py27,cov
 skipsdist = true
 
 [tox:jenkins]