aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore24
-rw-r--r--.gitreview5
-rw-r--r--.readthedocs.yaml20
-rw-r--r--INFO.yaml50
-rw-r--r--docs/.gitignore3
-rw-r--r--docs/Logging_User_Guide/logging_user_guide.rst1
-rw-r--r--docs/ONAP_Log_Analytics/onap_log_analytics.rst297
-rw-r--r--docs/_static/css/ribbon.css63
-rwxr-xr-xdocs/_static/favicon.icobin0 -> 2102 bytes
-rw-r--r--docs/_static/logo_onap_2017.pngbin0 -> 12278 bytes
-rw-r--r--docs/conf.py15
-rw-r--r--docs/conf.yaml7
-rw-r--r--docs/index.rst20
-rw-r--r--docs/media/configure-index-pattern.pngbin0 -> 83925 bytes
-rw-r--r--docs/media/data-table.pngbin0 -> 44014 bytes
-rw-r--r--docs/media/kibana_ui.pngbin0 -> 59431 bytes
-rw-r--r--docs/media/log-details.pngbin0 -> 56081 bytes
-rw-r--r--docs/media/log-expand.pngbin0 -> 90398 bytes
-rw-r--r--docs/media/logging-architecture.pngbin0 -> 702830 bytes
-rw-r--r--docs/media/onap-component-logs.pngbin0 -> 72004 bytes
-rw-r--r--docs/media/onap-discover.pngbin0 -> 145120 bytes
-rw-r--r--docs/media/search-component-logs.pngbin0 -> 92502 bytes
-rw-r--r--docs/media/search-source-logstash.pngbin0 -> 88155 bytes
-rw-r--r--docs/media/select-bucket-type.pngbin0 -> 47830 bytes
-rw-r--r--docs/media/split-row-data.pngbin0 -> 42252 bytes
-rw-r--r--docs/media/time-range.pngbin0 -> 73164 bytes
-rw-r--r--docs/media/visualization.pngbin0 -> 31711 bytes
-rw-r--r--docs/media/visualize-options.pngbin0 -> 48541 bytes
-rw-r--r--docs/release-notes.rst3
-rw-r--r--docs/requirements-docs.txt15
-rw-r--r--docs/tox.ini22
-rw-r--r--elasticstack/logstash/conf/onap-pipeline.properties32
-rw-r--r--pom.xml13
-rw-r--r--pylog/.gitignore4
-rw-r--r--pylog/onaplogging/colorFormatter.py274
-rw-r--r--pylog/onaplogging/logWatchDog.py131
-rw-r--r--pylog/onaplogging/marker/marker.py257
-rw-r--r--pylog/onaplogging/marker/markerFactory.py126
-rw-r--r--pylog/onaplogging/marker/markerFilter.py52
-rw-r--r--pylog/onaplogging/marker/markerHandler.py120
-rw-r--r--pylog/onaplogging/markerFormatter.py117
-rw-r--r--pylog/onaplogging/markerLogAdaptor.py161
-rw-r--r--pylog/onaplogging/mdcContext.py205
-rw-r--r--pylog/onaplogging/mdcformatter.py245
-rw-r--r--pylog/onaplogging/monkey.py20
-rw-r--r--pylog/onaplogging/utils/__init__.py0
-rw-r--r--pylog/onaplogging/utils/styles.py84
-rw-r--r--pylog/onaplogging/utils/system.py31
-rw-r--r--pylog/onaplogging/utils/tools.py32
-rw-r--r--pylog/pom.xml20
-rw-r--r--pylog/requirements.txt2
-rw-r--r--pylog/setup.py2
-rw-r--r--pylog/test_requirements.txt5
-rw-r--r--pylog/tests/test_color_formatter.py133
-rw-r--r--pylog/tests/test_example.py18
-rw-r--r--pylog/tests/test_log_watchdog.py91
-rw-r--r--pylog/tests/test_marker.py179
-rw-r--r--pylog/tests/test_marker_formatter.py67
-rw-r--r--pylog/tests/test_marker_log_adaptor.py76
-rw-r--r--pylog/tests/test_mdc_context.py189
-rw-r--r--pylog/tests/test_mdc_formatter.py108
-rw-r--r--pylog/tests/test_monkey.py47
-rw-r--r--pylog/tests/test_utils.py45
-rw-r--r--pylog/tox.ini27
-rw-r--r--pylog/version.properties4
-rw-r--r--reference/.classpath10
-rw-r--r--reference/.gitignore2
-rw-r--r--reference/.project44
-rw-r--r--reference/logging-demo/.classpath32
-rw-r--r--reference/logging-demo/.gitignore3
-rw-r--r--reference/logging-demo/.project44
-rw-r--r--reference/logging-demo/pom.xml457
-rw-r--r--reference/logging-docker-root/.project17
-rw-r--r--reference/logging-docker-root/pom.xml15
-rw-r--r--reference/logging-filter/logging-filter-base/pom.xml108
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java13
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractBaseMetricLogFilter.java134
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMDCSetupAspect.java78
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java89
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java2
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java1
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomFilter.java25
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomResponseStatus.java62
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ErrorCode.java40
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/FilteredMetricLogClientFilter.java62
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/HttpURLConnectionMetricUtil.java8
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java175
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java54
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledLogging.java32
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTaskException.java45
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspect.java47
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/SoapMetricLogHandler.java87
-rw-r--r--reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java60
-rw-r--r--reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java12
-rw-r--r--reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspectTest.java99
-rw-r--r--reference/logging-filter/logging-filter-spring/pom.xml122
-rw-r--r--reference/logging-filter/logging-filter-spring/src/main/java/org/onap/logging/filter/spring/SpringScheduledTasksMDCSetupAspect.java49
-rw-r--r--reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java6
-rw-r--r--reference/logging-filter/pom.xml430
-rw-r--r--reference/logging-kubernetes/.project17
-rw-r--r--reference/logging-kubernetes/pom.xml15
-rw-r--r--reference/logging-library/.classpath27
-rw-r--r--reference/logging-library/.gitignore2
-rw-r--r--reference/logging-library/.project53
-rw-r--r--reference/logging-library/pom.xml222
-rw-r--r--reference/logging-mock-service/.classpath27
-rw-r--r--reference/logging-mock-service/.gitignore2
-rw-r--r--reference/logging-mock-service/.project53
-rw-r--r--reference/logging-mock-service/pom.xml75
-rw-r--r--reference/logging-slf4j-demo/pom.xml322
-rw-r--r--reference/logging-slf4j/pom.xml180
-rw-r--r--reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java4
-rw-r--r--reference/pom.xml188
-rw-r--r--reference/provider/pom.xml15
-rw-r--r--releases/1.6.3.yaml4
-rw-r--r--releases/1.6.4.yaml5
-rw-r--r--releases/1.6.5.yaml5
-rw-r--r--releases/1.6.6.yaml5
-rw-r--r--releases/1.6.7.yaml5
-rw-r--r--releases/1.6.8.yaml5
-rw-r--r--releases/1.6.9.yaml5
-rw-r--r--version.properties2
122 files changed, 4921 insertions, 2243 deletions
diff --git a/.gitignore b/.gitignore
index 8a809f2..7d1bceb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,29 @@
-.idea
+# Maven
+target/
+build/
+
+# Vagrant
+.vagrant
+
+# IntelliJ
+.idea/
+*.iml
+
+# Eclipse
.project
.classpath
.settings
-*.iml
+
+# Python
+.tox/
+__pycache__/
+*.pyc
+.pytest_cache/
+
npm-debug.log
node_modules/
node_install/
test_output/
test-output/
-target/
dist/
-
+venv/ \ No newline at end of file
diff --git a/.gitreview b/.gitreview
new file mode 100644
index 0000000..9587901
--- /dev/null
+++ b/.gitreview
@@ -0,0 +1,5 @@
+[gerrit]
+host=gerrit.onap.org
+port=29418
+project=logging-analytics.git
+defaultbranch=master
diff --git a/.readthedocs.yaml b/.readthedocs.yaml
new file mode 100644
index 0000000..3797dc8
--- /dev/null
+++ b/.readthedocs.yaml
@@ -0,0 +1,20 @@
+---
+# .readthedocs.yml
+# Read the Docs configuration file
+# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
+# Required
+version: 2
+
+formats:
+ - htmlzip
+
+build:
+ image: latest
+
+python:
+ version: 3.7
+ install:
+ - requirements: docs/requirements-docs.txt
+
+sphinx:
+ configuration: docs/conf.py
diff --git a/INFO.yaml b/INFO.yaml
index 0fdb981..b0c36d5 100644
--- a/INFO.yaml
+++ b/INFO.yaml
@@ -2,7 +2,7 @@
project: 'logging-analytics'
project_creation_date: '2017-08-04'
project_category: ''
-lifecycle_state: 'Incubation'
+lifecycle_state: 'Unmaintained'
project_lead: &onap_logging-analytics_ptl
name: 'Prudence Au'
email: 'prudence.au@amdocs.com'
@@ -20,21 +20,15 @@ mailing_list:
tag: '<[sub-project_name]>'
realtime_discussion: ''
meetings:
- - type: 'zoom'
- agenda: 'https://wiki.onap.org/pages/viewpage.action?pageId=10784046'
- url: 'https://wiki.onap.org/pages/viewpage.action?pageId=10784046'
+ - type: 'n/a'
+ agenda: 'n/a'
+ url: 'n/a'
server: 'n/a'
channel: 'n/a'
- repeats: 'weekly'
- time: '15:00 UTC'
+ repeats: 'n/a'
+ time: 'n/a'
repositories:
- 'logging-analytics'
- - 'logging-analytics-pomba-pomba-aai-context-builder'
- - 'logging-analytics-pomba-pomba-audit-common'
- - 'logging-analytics-pomba-pomba-context-aggregator'
- - 'logging-analytics-pomba-pomba-network-discovery-context-builder'
- - 'logging-analytics-pomba-pomba-sdc-context-builder'
- - 'logging-analytics-pomba-pomba-sdnc-context-builder'
committers:
- <<: *onap_logging-analytics_ptl
- name: 'Avdhut Kholkar'
@@ -57,6 +51,26 @@ committers:
company: 'Amdocs'
id: 'prioux'
timezone: 'Canada/Eastern'
+ - name: 'Kevin Smokowski'
+ email: 'ks6305@att.com'
+ company: 'ATT'
+ id: 'nullop'
+ timezone: 'America/New York'
+ - name: 'Brittany Plummer'
+ email: 'bp896r@att.com'
+ company: 'ATT'
+ id: 'bp896r'
+ timezone: 'America/New York'
+ - name: 'Kapil Singal'
+ email: 'ks220y@att.com'
+ company: 'ATT'
+ id: 'ks220y'
+ timezone: 'America/New York'
+ - name: 'Elena Kuleshov'
+ email: 'ek1439@att.com'
+ company: 'ATT'
+ id: 'ek1439'
+ timezone: 'America/New York'
tsc:
approval: 'https://lists.onap.org/pipermail/onap-tsc'
changes:
@@ -87,3 +101,15 @@ tsc:
- type: 'Addition'
name: 'Pierre Rioux'
link: 'https://lists.onap.org/g/onap-tsc/message/5359'
+ - type: 'Addition'
+ name: Kevin Smokowski
+ link: 'https://lists.onap.org/g/onap-tsc/message/5722'
+ - type: 'Addition'
+ name: Brittany Plummer
+ link: 'https://lists.onap.org/g/onap-tsc/message/6691'
+ - type: 'Addition'
+ name: Kapil Singal
+ link: 'https://lists.onap.org/g/onap-tsc/message/6964'
+ - type: 'Addition'
+ name: Elena Kuleshov
+ link: 'https://lists.onap.org/g/onap-tsc/message/6964'
diff --git a/docs/.gitignore b/docs/.gitignore
new file mode 100644
index 0000000..43ca5b6
--- /dev/null
+++ b/docs/.gitignore
@@ -0,0 +1,3 @@
+/.tox
+/_build/*
+/__pycache__/*
diff --git a/docs/Logging_User_Guide/logging_user_guide.rst b/docs/Logging_User_Guide/logging_user_guide.rst
index a78fe75..539ae9f 100644
--- a/docs/Logging_User_Guide/logging_user_guide.rst
+++ b/docs/Logging_User_Guide/logging_user_guide.rst
@@ -5,6 +5,7 @@
.. This work is licensed under a Creative Commons Attribution 4.0 International License.
.. http://creativecommons.org/licenses/by/4.0
.. Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+.. _logging_user_guide:
Logging User Guide
==================
diff --git a/docs/ONAP_Log_Analytics/onap_log_analytics.rst b/docs/ONAP_Log_Analytics/onap_log_analytics.rst
new file mode 100644
index 0000000..15ac9c5
--- /dev/null
+++ b/docs/ONAP_Log_Analytics/onap_log_analytics.rst
@@ -0,0 +1,297 @@
+.. This work is licensed under a Creative Commons Attribution 4.0
+.. International License. http://creativecommons.org/licenses/by/4.0
+.. Copyright © 2017-2020 Aarna Networks, Inc.
+.. Links
+.. _Elastic Stack: https://www.elastic.co/products
+.. _Elasticsearch: https://www.elastic.co/elasticsearch
+.. _Kibana Discover: https://www.elastic.co/guide/en/kibana/current/discover.html
+
+
+ONAP Log Analytics
+##################
+
+The purpose of the ONAP Log Analytics project is to provide standardized logs across all ONAP components using ELK framework for log capture, indexing and presentation/search.
+
+Logging Architecture
+====================
+
+ONAP uses ELK stack for centralized logging for all the ONAP components. ELK stands for Elastic search, Logstash, Kibana. The aggregated logging framework uses Filebeat to send logs from each pod to the ELK stack where they are processed and stored. This requires each pod to have an additional container which will run Filebeat, and for the necessary log files to be accessible between containers. We use filebeat as a side car container for all the onap components to push logs to the logstash node port.
+
+|logging-architecture|
+
+Deploy ONAP Logging Component
+=============================
+
+Following are the detailed steps to install the logging component and access the ONAP component’s logs via centralized dashboard UI called Kibana discover.
+
+.. note::
+
+ The logging analytics stack (Elasticsearch, Logstash, Kibana) is provided as part of the OOM deployment via the component log.
+
+1) Check if the logging component is deployed
+---------------------------------------------
+
+Run the below command to check if the logging component is installed.
+
+::
+
+ helm list | grep -i log
+ dev-log 1 Thu Dec 10 10:47:05 2020 DEPLOYED log-6.0.0 onap
+
+If it does not return anything that means log component is not deployed.
+
+2) Deploy log component (If it is not deployed)
+-----------------------------------------------
+
+a) Get the helm chart for log component
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+::
+
+ helm search | grep log
+ local/log 6.0.0 ONAP Logging ElasticStack
+
+b) Deploy log component
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+::
+
+ helm upgrade --install dev-log local/log --namespace onap --timeout 900 --set 'flavor=unlimited'
+
+3) Verify if log component is deployed now
+------------------------------------------
+
+a) Verify the log component deployment status
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+::
+
+ helm list | grep -i log
+ dev-log 1 Thu Dec 10 10:47:05 2020 DEPLOYED log-6.0.0 onap
+
+The status should show as deployed.
+
+b) Verify that all the logging pods are up and running
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+::
+
+ kubectl get pod -n onap | grep log-
+ dev-log-elasticsearch-6c8f844446-rjpvs 1/1 Running 0 10d
+ dev-log-kibana-6d57c74667-t6hm2 1/1 Running 0 10d
+ dev-log-logstash-7fb656b4c9-2mttc 1/1 Running 0 10d
+ dev-log-logstash-7fb656b4c9-jdkdf 1/1 Running 0 10d
+ dev-log-logstash-7fb656b4c9-zmtl7 1/1 Running 0 10d
+ dev-modeling-etsicatalog-744b5b5955-5khg8 2/2 Running 1 12d
+ dev-so-catalog-db-adapter-988fb5db4-qzgss 1/1 Running 0 11d
+
+All the pods should be up and running.
+
+c) Verify that all the log pods are exposed
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+::
+
+ kubectl get svc -n onap | grep log-
+ log-es NodePort 10.43.85.25 <none> 9200:30254/TCP 10d
+ log-es-tcp ClusterIP 10.43.26.175 <none> 9300/TCP 10d
+ log-kibana NodePort 10.43.189.12 <none> 5601:30253/TCP 10d
+ log-ls NodePort 10.43.160.207 <none> 5044:30255/TCP 10d
+ log-ls-http ClusterIP 10.43.208.52 <none> 9600/TCP 10d
+
+All the pods are exposed.
+
+ONAP components with filebeat containers
+========================================
+
+As mentioned already ONAP logging framework uses Filebeat to send logs from each pod to the ELK stack where they are processed and stored. Below is the list of ONAP components with filebeat containers.
+
+::
+
+ kubectl get pods -n onap | grep 2/2
+
+ dep-dcae-hv-ves-collector-868f7b7ffc-9mgk6 2/2 Running 0 12d
+ dep-dcae-prh-8499df6dcf-x2bz7 2/2 Running 0 12d
+ dep-dcae-tca-analytics-cc44cb89-8qg2p 2/2 Running 0 12d
+ dep-dcae-tcagen2-6d59df6fb4-85qtr 2/2 Running 0 12d
+ dep-dcae-ves-collector-55f5b4f469-jd5xd 2/2 Running 0 12d
+ dev-aaf-sms-vault-0 2/2 Running 0 12d
+ dev-aai-babel-79d8d4f674-9l4h6 2/2 Running 0 12d
+ dev-aai-data-router-66d8897bc6-6vw77 2/2 Running 0 12d
+ dev-aai-graphadmin-7664654967-t78kb 2/2 Running 0 12d
+ dev-aai-modelloader-7486f7c665-8bmvp 2/2 Running 0 12d
+ dev-aai-resources-5c996776fd-nvdbq 2/2 Running 0 12d
+ dev-aai-schema-service-c9464576-5z4nh 2/2 Running 0 12d
+ dev-aai-search-data-6c899c7466-8qvkx 2/2 Running 0 12d
+ dev-aai-sparky-be-8f5569986-j88kv 2/2 Running 0 12d
+ dev-aai-traversal-6b89655c6d-r8kkf 2/2 Running 0 12d
+ dev-dcae-dashboard-7c4d647c68-hpqqr 2/2 Running 0 12d
+ dev-dcae-deployment-handler-68ff4db5d5-jk62q 2/2 Running 0 12d
+ dev-dcae-inventory-api-6d584b55d5-lzh8m 2/2 Running 0 12d
+ dev-dcae-policy-handler-587bb84c49-9gpd4 2/2 Running 0 12d
+ dev-dcaemod-genprocessor-78c588cfb5-9v5q2 2/2 Running 0 12d
+ dev-dmaap-dr-node-0 2/2 Running 0 12d
+ dev-dmaap-dr-prov-745f65979c-vw97l 2/2 Running 0 12d
+ dev-esr-server-759ccd4fcd-tvq48 2/2 Running 0 12d
+ dev-modeling-etsicatalog-744b5b5955-5khg8 2/2 Running 1 12d
+ dev-msb-discovery-5fb7c77c97-khl72 2/2 Running 0 12d
+ dev-msb-eag-bdff68dbf-7rprj 2/2 Running 0 12d
+ dev-msb-iag-5cd9744464-nq5dz 2/2 Running 0 12d
+ dev-multicloud-6b6d7f9f4c-szbsx 2/2 Running 0 12d
+ dev-multicloud-azure-56d85dfbf-jshpp 2/2 Running 0 12d
+ dev-multicloud-k8s-5498c868b4-2vzw8 2/2 Running 0 12d
+ dev-multicloud-pike-6697844fb5-5ckj7 2/2 Running 0 12d
+ dev-multicloud-vio-69d6cb7cfd-g87xh 2/2 Running 0 12d
+ dev-pdp-0 2/2 Running 0 12d
+ dev-policy-5f85767b74-c5btk 2/2 Running 0 12d
+ dev-portal-app-6f5cbdbf6f-z5w9g 2/2 Running 0 12d
+ dev-portal-sdk-79ffcff9d5-56xj8 2/2 Running 0 12d
+ dev-sdc-be-68b4dddf69-qz9d6 2/2 Running 0 9d
+ dev-sdc-dcae-be-95dcd7ccf-kk9pc 2/2 Running 0 9d
+ dev-sdc-dcae-dt-6c8568db54-4jvgv 2/2 Running 0 9d
+ dev-sdc-dcae-fe-66894f8765-dx2t6 2/2 Running 0 9d
+ dev-sdc-dcae-tosca-lab-59d6f8b74f-2985g 2/2 Running 0 9d
+ dev-sdc-fe-59977f556d-qmszf 2/2 Running 0 9d
+ dev-sdc-onboarding-be-679c4df66c-4kskk 2/2 Running 0 9d
+ dev-sdc-wfd-fe-54f8596994-zvpgp 2/2 Running 0 9d
+ dev-sdnc-0 2/2 Running 0 12d
+ dev-sdnrdb-coordinating-only-544c5bc596-49gw7 2/2 Running 0 12d
+ dev-so-6cb779c78b-fqrkx 2/2 Running 0 11d
+ dev-so-bpmn-infra-6b8cdb54f7-vcm5f 2/2 Running 0 11d
+ dev-so-openstack-adapter-7584878db6-srpjs 2/2 Running 0 11d
+ dev-so-sdc-controller-747f4485f9-tjwhb 2/2 Running 0 11d
+ dev-so-sdnc-adapter-5c5f98bf7f-cbd2c 2/2 Running 0 11d
+ dev-vfc-generic-vnfm-driver-7f459b74cf-2kcq9 2/2 Running 0 12d
+ dev-vfc-huawei-vnfm-driver-5b57557467-5j87x 2/2 Running 0 12d
+ dev-vfc-juju-vnfm-driver-6455bd954b-zbfwh 2/2 Running 0 12d
+ dev-vfc-nslcm-6d96959f5f-9fpdm 2/2 Running 0 12d
+ dev-vfc-resmgr-7768d6889d-rlw87 2/2 Running 0 12d
+ dev-vfc-vnflcm-86f65c4459-gz9q7 2/2 Running 0 12d
+ dev-vfc-vnfmgr-5cb6467fdd-wbcfb 2/2 Running 0 12d
+ dev-vfc-vnfres-5c5c69885b-bh59q 2/2 Running 1 12d
+ dev-vfc-zte-vnfm-driver-66c978dfc7-l57vq 2/2 Running 0 12d
+ dev-vid-688f46488f-ctlwh 2/2 Running 0 12d
+
+For examples, let’s look at SO component and check the filebeat container details.
+
+::
+
+ kubectl get pods -n onap | grep 'dev-so-'
+ dev-so-6cb779c78b-fqrkx 2/2 Running 0 11d
+ dev-so-appc-orchestrator-5df5cc4f9b-2mwgm 1/1 Running 0 11d
+ dev-so-bpmn-infra-6b8cdb54f7-vcm5f 2/2 Running 0 11d
+ dev-so-catalog-db-adapter-988fb5db4-qzgss 1/1 Running 0 11d
+ dev-so-mariadb-config-job-zqp56 0/1 Completed 0 12d
+ dev-so-monitoring-c69f6bdf8-ldxn8 1/1 Running 0 11d
+ dev-so-nssmf-adapter-6fdbbbbf57-6prlq 1/1 Running 0 11d
+ dev-so-openstack-adapter-7584878db6-srpjs 2/2 Running 0 11d
+ dev-so-request-db-adapter-8467c89c76-g4hgt 1/1 Running 0 11d
+ dev-so-sdc-controller-747f4485f9-tjwhb 2/2 Running 0 11d
+ dev-so-sdnc-adapter-5c5f98bf7f-cbd2c 2/2 Running 0 11d
+ dev-so-ve-vnfm-adapter-7fb59df855-98n98 1/1 Running 0 11d
+ dev-so-vfc-adapter-5cd8454bb6-gvklj 1/1 Running 0 11d
+ dev-so-vnfm-adapter-678f655bff-q9cr9 1/1 Running 0 11d
+
+In the above output notice that there are 3 pods with status as 2/2 running, which means those pods has 2 containers in it and these are pods which contains filebeat containers.
+
+Now use the following command to check the filebeat container details for one of the SO pod.
+
+::
+
+ kubectl describe pod -n onap dev-so-6cb779c78b-fqrkx | grep -i filebeat
+ so-filebeat-onap:
+ Image: docker.elastic.co/beats/filebeat:5.5.0
+ Image ID: docker-pullable://docker.elastic.co/beats/filebeat@sha256:fe7602b641ed8ee288f067f7b31ebde14644c4722d9f7960f176d621097a5942
+ /usr/share/filebeat/data from dev-so-data-filebeat (rw) /usr/share/filebeat/filebeat.yml from dev-so-filebeat-conf (rw,path="filebeat.yml")
+ dev-so-filebeat-conf:
+ Name: dev-so-so-filebeat-configmap
+ dev-so-data-filebeat:
+
+So, we have seen that ELK stack and filebeat containers are being deployed and configured as part of the OOM deployment.
+
+Access Kibana UI to visualize the ONAP component’s logs
+=======================================================
+
+The frontend UI, Kibana, can be accessed from a web browser on the port 30253. Below is the command showing that the log-kibana service is exposed to a Nodeport 30253.
+
+::
+
+ kubectl get svc -n onap | grep log-kibana
+ log-kibana NodePort 10.43.189.12 <none> 5601:30253/TCP 10d
+
+Follow the below steps to access Kibana UI and view the logs
+------------------------------------------------------------
+
+1) To launch the Kibana UI, navigate to http://<vm-ip-address>:30253 in your browser. Refer the below screen shot for the same.
+
+|image1|
+
+2) Provide the Index name or pattern as logstash-* and time filter field as timestamp and then click on create button.
+
+|image2|
+
+3) Click on Visualize in the left pane and then click on create a visualization.
+
+|image3|
+
+4) Now click on Data table as shown below.
+
+|image4|
+
+5) Now you will choose the search source. You can see the logstash-* is available in list,click on it.
+
+|image5|
+
+6) Select the bucket type as split rows as shown in the below screen shot.
+
+|image6|
+
+7) Provide the following details.
+
+|image7|
+
+8) Click on options, enter the values for per page and click on apply changes.
+
+|image8|
+
+9) Click on clock icon in the top right corner, then select the time range as last 7 days. Click on Auto-refresh and select the desired auto-refresh frequency and then click the apply changes button.
+
+|image9|
+
+10) Now you can see, it has populated the list of all onap component logs.
+
+|image10|
+
+11) Click on Discover in the left pane and it will populate the logs.
+
+|image11|
+
+12) You can search the logs for any component. Just provide the component name in the search field. For example we have entered SO.
+
+|image12|
+
+13) Now you can see the log details by clicking on the expand sign for any particular date and time.
+
+|image13|
+
+|image14|
+
+
+
+
+.. |logging-architecture| image:: ../media/logging-architecture.png
+.. |image1| image:: ../media/kibana_ui.png
+.. |image2| image:: ../media/configure-index-pattern.png
+.. |image3| image:: ../media/visualization.png
+.. |image4| image:: ../media/data-table.png
+.. |image5| image:: ../media/search-source-logstash.png
+.. |image6| image:: ../media/select-bucket-type.png
+.. |image7| image:: ../media/split-row-data.png
+.. |image8| image:: ../media/visualize-options.png
+.. |image9| image:: ../media/time-range.png
+.. |image10| image:: ../media/onap-component-logs.png
+.. |image11| image:: ../media/onap-discover.png
+.. |image12| image:: ../media/search-component-logs.png
+.. |image13| image:: ../media/log-expand.png
+.. |image14| image:: ../media/log-details.png
+
diff --git a/docs/_static/css/ribbon.css b/docs/_static/css/ribbon.css
new file mode 100644
index 0000000..6008cb1
--- /dev/null
+++ b/docs/_static/css/ribbon.css
@@ -0,0 +1,63 @@
+.ribbon {
+ z-index: 1000;
+ background-color: #a00;
+ overflow: hidden;
+ white-space: nowrap;
+ position: fixed;
+ top: 25px;
+ right: -50px;
+ -webkit-transform: rotate(45deg);
+ -moz-transform: rotate(45deg);
+ -ms-transform: rotate(45deg);
+ -o-transform: rotate(45deg);
+ transform: rotate(45deg);
+ -webkit-box-shadow: 0 0 10px #888;
+ -moz-box-shadow: 0 0 10px #888;
+ box-shadow: 0 0 10px #888;
+
+}
+
+.ribbon a {
+ border: 1px solid #faa;
+ color: #fff;
+ display: block;
+ font: bold 81.25% 'Helvetica Neue', Helvetica, Arial, sans-serif;
+ margin: 1px 0;
+ padding: 10px 50px;
+ text-align: center;
+ text-decoration: none;
+ text-shadow: 0 0 5px #444;
+ transition: 0.5s;
+}
+
+.ribbon a:hover {
+ background: #c11;
+ color: #fff;
+}
+
+
+/* override table width restrictions */
+@media screen and (min-width: 767px) {
+
+ .wy-table-responsive table td, .wy-table-responsive table th {
+ /* !important prevents the common CSS stylesheets from overriding
+ this as on RTD they are loaded after this stylesheet */
+ white-space: normal !important;
+ }
+
+ .wy-table-responsive {
+ overflow: visible !important;
+ }
+}
+
+@media screen and (max-width: 767px) {
+ .wy-table-responsive table td {
+ white-space: nowrap;
+ }
+}
+
+/* fix width of the screen */
+
+.wy-nav-content {
+ max-width: none;
+}
diff --git a/docs/_static/favicon.ico b/docs/_static/favicon.ico
new file mode 100755
index 0000000..cb712eb
--- /dev/null
+++ b/docs/_static/favicon.ico
Binary files differ
diff --git a/docs/_static/logo_onap_2017.png b/docs/_static/logo_onap_2017.png
new file mode 100644
index 0000000..5d064f4
--- /dev/null
+++ b/docs/_static/logo_onap_2017.png
Binary files differ
diff --git a/docs/conf.py b/docs/conf.py
new file mode 100644
index 0000000..5371015
--- /dev/null
+++ b/docs/conf.py
@@ -0,0 +1,15 @@
+from docs_conf.conf import *
+
+branch = 'latest'
+master_doc = 'index'
+
+linkcheck_ignore = [
+ 'http://localhost',
+]
+
+intersphinx_mapping = {}
+
+html_last_updated_fmt = '%d-%b-%y %H:%M'
+
+def setup(app):
+ app.add_stylesheet("css/ribbon.css")
diff --git a/docs/conf.yaml b/docs/conf.yaml
new file mode 100644
index 0000000..ab59281
--- /dev/null
+++ b/docs/conf.yaml
@@ -0,0 +1,7 @@
+---
+project_cfg: onap
+project: onap
+
+# Change this to ReleaseBranchName to modify the header
+default-version: latest
+#
diff --git a/docs/index.rst b/docs/index.rst
index d6fe682..3328fe2 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1,9 +1,11 @@
-.. This work is licensed under a Creative Commons Attribution 4.0 International License.
-
-Logging Documentation Repository
-----------------------------
-.. toctree::
- :maxdepth: 2
-
- Logging_Enhancements_Project/logging_enhancements_project.rst
- Logging_User_Guide/logging_user_guide.rst
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+.. _master_index:
+
+Logging Documentation Repository
+----------------------------
+.. toctree::
+ :maxdepth: 2
+
+ Logging_Enhancements_Project/logging_enhancements_project.rst
+ Logging_User_Guide/logging_user_guide.rst
+ ONAP_Log_Analytics/onap_log_analytics.rst
diff --git a/docs/media/configure-index-pattern.png b/docs/media/configure-index-pattern.png
new file mode 100644
index 0000000..e664a7d
--- /dev/null
+++ b/docs/media/configure-index-pattern.png
Binary files differ
diff --git a/docs/media/data-table.png b/docs/media/data-table.png
new file mode 100644
index 0000000..406edeb
--- /dev/null
+++ b/docs/media/data-table.png
Binary files differ
diff --git a/docs/media/kibana_ui.png b/docs/media/kibana_ui.png
new file mode 100644
index 0000000..ea6dd5b
--- /dev/null
+++ b/docs/media/kibana_ui.png
Binary files differ
diff --git a/docs/media/log-details.png b/docs/media/log-details.png
new file mode 100644
index 0000000..40c9e11
--- /dev/null
+++ b/docs/media/log-details.png
Binary files differ
diff --git a/docs/media/log-expand.png b/docs/media/log-expand.png
new file mode 100644
index 0000000..040bd59
--- /dev/null
+++ b/docs/media/log-expand.png
Binary files differ
diff --git a/docs/media/logging-architecture.png b/docs/media/logging-architecture.png
new file mode 100644
index 0000000..9a66271
--- /dev/null
+++ b/docs/media/logging-architecture.png
Binary files differ
diff --git a/docs/media/onap-component-logs.png b/docs/media/onap-component-logs.png
new file mode 100644
index 0000000..fbc10c6
--- /dev/null
+++ b/docs/media/onap-component-logs.png
Binary files differ
diff --git a/docs/media/onap-discover.png b/docs/media/onap-discover.png
new file mode 100644
index 0000000..7981729
--- /dev/null
+++ b/docs/media/onap-discover.png
Binary files differ
diff --git a/docs/media/search-component-logs.png b/docs/media/search-component-logs.png
new file mode 100644
index 0000000..718a258
--- /dev/null
+++ b/docs/media/search-component-logs.png
Binary files differ
diff --git a/docs/media/search-source-logstash.png b/docs/media/search-source-logstash.png
new file mode 100644
index 0000000..4e98c25
--- /dev/null
+++ b/docs/media/search-source-logstash.png
Binary files differ
diff --git a/docs/media/select-bucket-type.png b/docs/media/select-bucket-type.png
new file mode 100644
index 0000000..3adf355
--- /dev/null
+++ b/docs/media/select-bucket-type.png
Binary files differ
diff --git a/docs/media/split-row-data.png b/docs/media/split-row-data.png
new file mode 100644
index 0000000..b87e151
--- /dev/null
+++ b/docs/media/split-row-data.png
Binary files differ
diff --git a/docs/media/time-range.png b/docs/media/time-range.png
new file mode 100644
index 0000000..f1c985f
--- /dev/null
+++ b/docs/media/time-range.png
Binary files differ
diff --git a/docs/media/visualization.png b/docs/media/visualization.png
new file mode 100644
index 0000000..d54c75b
--- /dev/null
+++ b/docs/media/visualization.png
Binary files differ
diff --git a/docs/media/visualize-options.png b/docs/media/visualize-options.png
new file mode 100644
index 0000000..bed8267
--- /dev/null
+++ b/docs/media/visualize-options.png
Binary files differ
diff --git a/docs/release-notes.rst b/docs/release-notes.rst
index 62d2c23..fabe723 100644
--- a/docs/release-notes.rst
+++ b/docs/release-notes.rst
@@ -1,6 +1,7 @@
.. This work is licensed under a Creative Commons Attribution 4.0 International License.
.. http://creativecommons.org/licenses/by/4.0
.. Copyright 2017 Bell Canada & Amdocs Intellectual Property. All rights reserved.
+.. _release_notes:
.. Links
.. _release-notes-label:
@@ -370,7 +371,7 @@ Casablanca
**Known Issues**
- `LOG-913 <https://jira.onap.org/browse/LOG-913>`_ POMBA: 1 of 11 pods failing on sequenced startup on 3.0.0-ONAP - pomba is 22 on the order - looks timing related
- - `LOG-950 <https://jira.onap.org/browse/LOG-950>`_ LOG-950 upped the numbers from 10 to 30 – for intermittent deploy timing – this is an issue for several projects since 3.0.0-ONAP - the solution is a sequenced 5h deploy via `cd.sh <https://git.onap.org/logging-analytics/tree/deploy/cd.sh#n228>`_ and/or better vms for now until the `dependencies <https://wiki.onap.org/display/DW/Log+Streaming+Compliance+and+API#LogStreamingComplianceandAPI-DeploymentDependencyTree-Containerlevel>`_ and jobs are refactored into helm hooks
+ - `LOG-950 <https://jira.onap.org/browse/LOG-950>`_ LOG-950 upped the numbers from 10 to 30 - for intermittent deploy timing - this is an issue for several projects since 3.0.0-ONAP - the solution is a sequenced 5h deploy via `cd.sh <https://git.onap.org/logging-analytics/tree/deploy/cd.sh#n228>`_ and/or better vms for now until the `dependencies <https://wiki.onap.org/display/DW/Log+Streaming+Compliance+and+API#LogStreamingComplianceandAPI-DeploymentDependencyTree-Containerlevel>`_ and jobs are refactored into helm hooks
**Security Notes**
- all three nodeports for kibana, context builder and data-router are open by default for now
diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt
new file mode 100644
index 0000000..b3188dd
--- /dev/null
+++ b/docs/requirements-docs.txt
@@ -0,0 +1,15 @@
+tox
+Sphinx
+doc8
+docutils
+setuptools
+six
+sphinx_rtd_theme>=0.4.3
+sphinxcontrib-blockdiag
+sphinxcontrib-needs>=0.2.3
+sphinxcontrib-nwdiag
+sphinxcontrib-seqdiag
+sphinxcontrib-swaggerdoc
+sphinxcontrib-plantuml
+sphinx_bootstrap_theme
+lfdocs-conf
diff --git a/docs/tox.ini b/docs/tox.ini
new file mode 100644
index 0000000..edac8c3
--- /dev/null
+++ b/docs/tox.ini
@@ -0,0 +1,22 @@
+[tox]
+minversion = 1.6
+envlist = docs,
+skipsdist = true
+
+[testenv:docs]
+basepython = python3
+deps = -r{toxinidir}/requirements-docs.txt
+commands =
+ sphinx-build -b html -n -d {envtmpdir}/doctrees ./ {toxinidir}/_build/html
+ echo "Generated docs available in {toxinidir}/_build/html"
+whitelist_externals =
+ echo
+ git
+ sh
+
+[testenv:docs-linkcheck]
+basepython = python3
+#deps = -r{toxinidir}/requirements-docs.txt
+commands = echo "Link Checking not enforced"
+#commands = sphinx-build -b linkcheck -d {envtmpdir}/doctrees ./ {toxinidir}/_build/linkcheck
+whitelist_externals = echo
diff --git a/elasticstack/logstash/conf/onap-pipeline.properties b/elasticstack/logstash/conf/onap-pipeline.properties
index c411122..e9ca191 100644
--- a/elasticstack/logstash/conf/onap-pipeline.properties
+++ b/elasticstack/logstash/conf/onap-pipeline.properties
@@ -5,53 +5,53 @@ filebeat_port = 5044
## Enable encryption. Default false.
#filebeat_ssl = true
-
+
## ssl certificate path.
#filebeat_ssl_certificate = "/etc/ssl/private/server.crt"
-
+
## SSL key to use.
#filebeat_ssl_key = "/etc/ssl/private/server.key"
-
+
##SSL key passphrase to use.
#filebeat_ssl_key_passphrase = "abcd"
-
+
## Value can be any of: none, peer, force_peer.
#filebeat_ssl_verify_mode = force_peer
######### Elasticsearch output plugin configurations #########
### ES Security configurations ###
-
+
es_user = "elastic"
es_password = "changeme"
## Enable SSL/TLS secured communication to Elasticsearch cluster.
## Default is not set which in that case depends on the protocol specified in hosts list
#es_ssl = true
-
+
## The .cer or .pem file to validate the server’s certificate
#es_cacert = "/etc/pki/client/cert.pem"
-
+
## The keystore used to present a certificate to the server. It can be either .jks or .p12
#es_keystore = "/etc/pki/client/key.p12"
#es_keystore_password = "abcd"
-
+
## Option to validate the server’s certificate. Default is true
#es_ssl_certificate_verification = true
-
+
## The JKS truststore to validate the server’s certificate.
#es_truststore = "/etc/pki/client/cacerts.jks"
#es_truststore_password = "abcd"
-
-
+
+
### Elasticsearchcluster and host configurations ###
-#can specify one or a list of hosts. If sniffing is set, one is enough and others will be auto-discovered
-##Also protocol can be specified like ["http://10.247.186.12:9200"]
-es_hosts = ["10.247.186.12:9200"]
+#can specify one or a list of hosts. If sniffing is set, one is enough and others will be auto-discovered
+##Also protocol can be specified like ["http://<YOUR_ELASTICSEARCH_SERVER>:9200"]
+es_hosts = ["<YOUR_ELASTICSEARCH_SERVER>:9200"]
## Set the address of a forward HTTP proxy.
-#es_proxy = "https://genproxy.amdocs.com:8080"
-
+#es_proxy = "https://<YOUR_PROXY_SERVER>:8080"
+
##Use this if you must run Elasticsearch behind a proxy that remaps the root path for the Elasticsearch HTTP API lives
#es_path = ?? \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d27e5d5..f86b273 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,17 +1,20 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
<parent>
- <groupId>org.onap.oparent</groupId>
- <artifactId>oparent</artifactId>
- <version>2.0.0</version>
+ <groupId>org.onap.oparent</groupId>
+ <artifactId>oparent</artifactId>
+ <version>2.0.0</version>
</parent>
+
<groupId>org.onap.logging-analytics</groupId>
<artifactId>logging-analytics</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
<packaging>pom</packaging>
- <version>1.6.2-SNAPSHOT</version>
+
<name>logging-analytics</name>
- <url>http://maven.apache.org</url>
+
<modules>
<module>reference</module>
<module>pylog</module>
diff --git a/pylog/.gitignore b/pylog/.gitignore
new file mode 100644
index 0000000..9d5ff4e
--- /dev/null
+++ b/pylog/.gitignore
@@ -0,0 +1,4 @@
+.coverage
+.tox/
+__pycache__/
+tests/__pycache__/
diff --git a/pylog/onaplogging/colorFormatter.py b/pylog/onaplogging/colorFormatter.py
index 64e220a..5de0d60 100644
--- a/pylog/onaplogging/colorFormatter.py
+++ b/pylog/onaplogging/colorFormatter.py
@@ -13,129 +13,207 @@
# limitations under the License.
import os
-import sys
-import logging
-from logging import Formatter
+from logging import Formatter, LogRecord
+from deprecated import deprecated
+from warnings import warn
+from typing import Optional, Union, Dict
-ATTRIBUTES = {
- 'normal': 0,
- 'bold': 1,
- 'underline': 4,
- 'blink': 5,
- 'invert': 7,
- 'hide': 8,
+from onaplogging.utils.system import is_above_python_2_7, is_above_python_3_2
+from onaplogging.utils.styles import (
+ ATTRIBUTES,
+ HIGHLIGHTS,
+ COLORS,
-}
+ ATTRIBUTE_TAG,
+ HIGHLIGHT_TAG,
+ COLOR_TAG,
+ RESET,
+ FMT_STR
+)
-HIGHLIGHTS = {
- 'black': 40,
- 'red': 41,
- 'green': 42,
- 'yellow': 43,
- 'blue': 44,
- 'purple': 45,
- 'cyan': 46,
- 'white': 47,
-}
-
-COLORS = {
-
- 'black': 30,
- 'red': 31,
- 'green': 32,
- 'yellow': 33,
- 'blue': 34,
- 'purple': 35,
- 'cyan': 36,
- 'white': 37,
-}
-
-COLOR_TAG = "color"
-HIGHLIGHT_TAG = "highlight"
-ATTRIBUTE_TAG = "attribute"
+class BaseColorFormatter(Formatter):
+ """Text color formatter class.
+
+ Wraps the logging. Uses Git shell coloring codes. Doesn't support Windows
+ CMD yet. If `fmt` is not suppied, the `style` is used. Eventually converts
+ a LogRecord object to "colored" text.
+
+ TODO:
+ Support for Windows CMD.
+ Extends:
+ logging.Formatter
+ Properties:
+ style : '%', '{' or '$' formatting.
+ datefrmt : ISO8601-like (or RFC 3339-like) format.
+ Args:
+ fmt : human-readable format. Defaults to None.
+ datefmt : ISO8601-like (or RFC 3339-like) format. Defaults to None.
+ colorfmt : Color schemas for logging levels. Defaults to None.
+ style : '%', '{' or '$' formatting. Defaults to '%'.
+ Methods:
+ format : formats a LogRecord record.
+ _parseColor : selects colors based on a logging levels.
+ """
+
+ @property
+ def style(self):
+ # type: () -> str
+ return self.__style # name mangling with __ to avoid accidents
+
+ @property
+ def colorfmt(self):
+ # type: () -> str
+ return self.__colorfmt
+
+ @style.setter
+ def style(self, value):
+ # type: (str) -> None
+ """Assign new style."""
+ self.__style = value
+
+ @colorfmt.setter
+ def colorfmt(self, value):
+ # type: (str) -> None
+ """Assign new color format."""
+ self.__colorfmt = value
+
+ def __init__(self,
+ fmt=None, # type: Optional[str]
+ datefmt=None, # type: Optional[str]
+ colorfmt=None, # type: Optional[Dict]
+ style="%"): # type: Optional[str]
+
+ if is_above_python_3_2():
+ super(BaseColorFormatter, self). \
+ __init__(fmt=fmt, # noqa: E122
+ datefmt=datefmt,
+ style=style)
+
+ elif is_above_python_2_7():
+ super(BaseColorFormatter, self). \
+ __init__(fmt, datefmt) # noqa: E122
-RESET = '\033[0m'
+ else:
+ Formatter. \
+ __init__(self, fmt, datefmt) # noqa: E122
+ self.style = style
+ self.colorfmt = colorfmt
+ def format(self, record):
+ """Text formatter.
-def colored(text, color=None, on_color=None, attrs=None):
- # It can't support windows system cmd right now!
- # TODO: colered output on windows system cmd
- if os.name in ('nt', 'ce'):
- return text
+ Connects 2 methods. First it extract a level and a colors
+ assigned to this level in the BaseColorFormatter class.
+ Second it applied the colors to the text.
- if isinstance(attrs, str):
- attrs = [attrs]
+ Args:
+ record : an instance of a logged event.
+ Returns:
+ str : "colored" text (formatted text).
+ """
- if os.getenv('ANSI_COLORS_DISABLED', None) is None:
- fmt_str = '\033[%dm%s'
- if color is not None and isinstance(color, str):
- text = fmt_str % (COLORS.get(color, 0), text)
+ if is_above_python_2_7():
+ s = super(BaseColorFormatter, self). \
+ format(record)
- if on_color is not None and isinstance(on_color, str):
- text = fmt_str % (HIGHLIGHTS.get(on_color, 0), text)
+ else:
+ s = Formatter. \
+ format(self, record)
- if attrs is not None:
- for attr in attrs:
- text = fmt_str % (ATTRIBUTES.get(attr, 0), text)
+ color, highlight, attribute = self._parse_color(record)
- # keep origin color for tail spaces
- text += RESET
- return text
+ return apply_color(s, color, highlight, attrs=attribute)
+ def _parse_color(self, record):
+ # type: (LogRecord) -> (Optional[str], Optional[str], Optional[str])
+ """Color formatter based on the logging level.
-class BaseColorFormatter(Formatter):
+ This method formats the record according to its level
+ and a color format set for that level. If the level is
+ not found, then this method will eventually return None.
- def __init__(self, fmt=None, datefmt=None, colorfmt=None, style="%"):
- if sys.version_info > (3, 2):
- super(BaseColorFormatter, self).__init__(
- fmt=fmt, datefmt=datefmt, style=style)
- elif sys.version_info > (2, 7):
- super(BaseColorFormatter, self).__init__(fmt, datefmt)
- else:
- Formatter.__init__(self, fmt, datefmt)
+ Args:
+ record : an instance of a logged event.
+ Returns:
+ str : Colors.
+ str : Hightlight tag.
+ str : Attribute tag.
+ """
+ if self.colorfmt and \
+ isinstance(self.colorfmt, dict):
- self.style = style
- if sys.version_info > (3, 2):
- if self.style not in logging._STYLES:
- raise ValueError('Style must be one of: %s' % ','.join(
- logging._STYLES.keys()))
+ level = record.levelname
+ colors = self.colorfmt.get(level, None)
- self.colorfmt = colorfmt
+ if colors is not None and \
+ isinstance(colors, dict):
+ return (colors.get(COLOR_TAG, None), # noqa: E201
+ colors.get(HIGHLIGHT_TAG, None),
+ colors.get(ATTRIBUTE_TAG, None)) # noqa: E202
+ return None, None, None
+ @deprecated(reason="Will be removed. Use _parse_color(record) instead.")
def _parseColor(self, record):
"""
- color formatter for instance:
- {
- "logging-levelname":
- {
- "color":"<COLORS>",
- "highlight":"<HIGHLIGHTS>",
- "attribute":"<ATTRIBUTES>",
- }
- }
- :param record:
- :return: text color, background color, text attribute
+ Color based on logging level.
+ See method _parse_color(record).
"""
- if self.colorfmt and isinstance(self.colorfmt, dict):
+ return self._parse_color(record)
+
+
+def apply_color(text, # type: str
+ color=None, # type: Optional[str]
+ on_color=None, # type: Optional[str]
+ attrs=None): # type: Optional[Union[str, list]]
+ # type: (...) -> str
+ """Applies color codes to the text.
+
+ Args:
+ text : text to be "colored" (formatted).
+ color : Color in human-readable format. Defaults to None.
+ highlight : Hightlight color in human-readable format.
+ Previously called "on_color". Defaults to None.
+ attrs : Colors for attribute(s). Defaults to None.
+ Returns:
+ str : "colored" text (formatted text).
+ """
+ warn("`on_color` will be replaced with `highlight`.", DeprecationWarning)
+ highlight = on_color # replace the parameter and remove
- level = record.levelname
- colors = self.colorfmt.get(level, None)
+ if os.name in ('nt', 'ce'):
+ return text
- if colors is not None and isinstance(colors, dict):
- return colors.get(COLOR_TAG, None), \
- colors.get(HIGHLIGHT_TAG, None), \
- colors.get(ATTRIBUTE_TAG, None)
+ if isinstance(attrs, str):
+ attrs = [attrs]
- return None, None, None
+ ansi_disabled = os.getenv('ANSI_COLORS_DISABLED', None)
- def format(self, record):
+ if ansi_disabled is None:
- if sys.version_info > (2, 7):
- s = super(BaseColorFormatter, self).format(record)
- else:
- s = Formatter.format(self, record)
- color, on_color, attribute = self._parseColor(record)
- return colored(s, color, on_color, attrs=attribute)
+ if color is not None and \
+ isinstance(color, str):
+ text = FMT_STR % (COLORS.get(color, 0), text)
+
+ if highlight is not None and \
+ isinstance(highlight, str):
+ text = FMT_STR % (HIGHLIGHTS.get(highlight, 0), text)
+
+ if attrs is not None:
+ for attr in attrs:
+ text = FMT_STR % (ATTRIBUTES.get(attr, 0), text)
+
+ text += RESET # keep origin color for tail spaces
+
+ return text
+
+
+@deprecated(reason="Will be removed. Call apply_color(...) instead.")
+def colored(text, color=None, on_color=None, attrs=None):
+ """
+ Format text with color codes.
+ See method apply_color(text, color, on_color, attrs).
+ """
+ return apply_color(text, color, on_color, attrs)
diff --git a/pylog/onaplogging/logWatchDog.py b/pylog/onaplogging/logWatchDog.py
index f93dd12..42e8646 100644
--- a/pylog/onaplogging/logWatchDog.py
+++ b/pylog/onaplogging/logWatchDog.py
@@ -13,69 +13,131 @@
# limitations under the License.
import os
-import yaml
import traceback
+
from logging import config
+from typing import Dict, Optional, Any
+from deprecated import deprecated
+from warnings import warn
+
from watchdog.observers import Observer
-from watchdog.events import FileSystemEventHandler
+from watchdog.events import FileSystemEventHandler, FileSystemEvent
+
+from onaplogging.utils.tools import yaml_to_dict
-__all__ = ['patch_loggingYaml']
+__all__ = ['patch_loggingYaml'] # rename after the deprecated name changed
-def _yaml2Dict(filename):
+class FileEventHandlers(FileSystemEventHandler):
+ """Handler of the events in the file system.
- with open(filename, 'rt') as f:
- return yaml.load(f.read())
+ Use it to keep and eye on files in the file system.
+ Extends:
+ watchdog.events.FileSystemEventHandler
+ Properties:
+ filepath : The path to the file to be monitored.
+ current_config : Defaults to None.
+ Args:
+ filepath : The path to the file to be monitored.
+ """
-class FileEventHandlers(FileSystemEventHandler):
+ @property
+ def filepath(self):
+ # type: () -> str
+ return self._filepath
- def __init__(self, filepath):
+ @property
+ def current_config(self):
+ # type: () -> str
+ return self.currentConfig # deprecated, replace with _current_config
+
+ @filepath.setter
+ def filepath(self, value):
+ # type: (str) -> str
+ self._filepath = value
+
+ @current_config.setter
+ def current_config(self, value):
+ # type: (Dict) -> Dict
+ self.currentConfig = value
+
+ def __init__(self, filepath): # type: (str)
+ warn("Attribute currentConfig will be replaced with property"
+ "current_config. Use current_config instead.")
FileSystemEventHandler.__init__(self)
+
self.filepath = filepath
- self.currentConfig = None
+ self.current_config = None
def on_modified(self, event):
+ # type: (FileSystemEvent) -> None
+ """Configuration file actualizer.
+
+ When an event occurs in the file system the hadnler's filepath
+ is taken to update the configuration file. If the actualization
+ of the config file fails it will keep the old config file.
+
+ Args:
+ event : Represents an event on the file system.
+ Raises:
+ Exception : If the actualization of the config file fails.
+ """
try:
if event.src_path == self.filepath:
- newConfig = _yaml2Dict(self.filepath)
- print("reload logging configure file %s" % event.src_path)
- config.dictConfig(newConfig)
- self.currentConfig = newConfig
+
+ new_config = yaml_to_dict(self.filepath)
+ print("Reloading logging configuration file %s "
+ % event.src_path)
+
+ config.dictConfig(new_config)
+ self.current_config = new_config
except Exception:
traceback.print_exc()
print("Reuse the old configuration to avoid this"
"exception terminate program")
- if self.currentConfig:
- config.dictConfig(self.currentConfig)
+
+ if self.current_config:
+ config.dictConfig(self.current_config)
def _yamlConfig(filepath=None, watchDog=None):
+ # type: (Optional[str], Optional[Any]) -> None
+ """YAML configuration file loader.
- """
- load logging configureation from yaml file and monitor file status
+ Use it to monitor a file status in a directory. The watchdog can monitor
+ a YAML file status looking for modifications. If the watchdog is provided
+ start observing the directory. The new configuration file is saved as
+ current for the later reuse.
+
+ Args:
+ filepath : The path to the file to be monitored. Defaults to None.
+ watchDog : Monitors a YAML file identifier status. Defaults to None.
- :param filepath: logging yaml configure file absolute path
- :param watchDog: monitor yaml file identifier status
- :return:
+ Raises:
+ OSError : If the requested file in the filepath is not a file.
+ Exception : If watchdog observer setup or YAML coversion fails.
"""
- if os.path.isfile(filepath) is False:
- raise OSError("wrong file")
+
+ is_file = os.path.isfile(filepath)
+
+ if is_file is False:
+ raise OSError("%s is not a file" % (filepath))
dirpath = os.path.dirname(filepath)
event_handler = None
try:
- dictConfig = _yaml2Dict(filepath)
- # The watchdog could monitor yaml file status,if be modified
- # will send a notify then we could reload logging configuration
+ dictConfig = yaml_to_dict(filepath)
+ # Dev note: Will send a notify then we could reload logging config
if watchDog:
observer = Observer()
event_handler = FileEventHandlers(filepath)
- observer.schedule(event_handler=event_handler, path=dirpath,
+ observer.schedule(event_handler=event_handler,
+ path=dirpath,
recursive=False)
observer.setDaemon(True)
observer.start()
@@ -83,14 +145,23 @@ def _yamlConfig(filepath=None, watchDog=None):
config.dictConfig(dictConfig)
if event_handler:
- # here we keep the correct configuration for reusing
event_handler.currentConfig = dictConfig
except Exception:
traceback.print_exc()
-def patch_loggingYaml():
- # The patch to add yam config forlogginf and runtime
- # reload logging when modify yaml file
+def patch_logging_yaml():
+ # type: () -> None
+ """YAML configuration patch.
+
+ Adds the YAML configuration file loader
+ to logging.config module during runtime.
+ """
config.yamlConfig = _yamlConfig
+
+
+@deprecated(reason="Will be removed. Call patch_logging_yaml() instead.")
+def patch_loggingYaml():
+ """See patch_logging_yaml()"""
+ patch_logging_yaml()
diff --git a/pylog/onaplogging/marker/marker.py b/pylog/onaplogging/marker/marker.py
index 5414e21..17a3328 100644
--- a/pylog/onaplogging/marker/marker.py
+++ b/pylog/onaplogging/marker/marker.py
@@ -14,10 +14,30 @@
import abc
+from typing import Iterable, List, Optional, Union, Iterator
+from deprecated import deprecated
+from warnings import warn
+from logging import LogRecord
+
MARKER_TAG = "marker"
class Marker(object):
+ """Abstract class for defining the marker structure.
+
+ TODO:
+ after deprecated child methods are removed, rename them here.
+ Extends:
+ object
+ Method list:
+ getName
+ addChild
+ addChilds
+ removeChild
+ contains
+ Raises:
+ NotImplementedError
+ """
__metaclass__ = abc.ABCMeta
@@ -51,92 +71,235 @@ class Marker(object):
class BaseMarker(Marker):
+ """Basic marker class.
+
+ It is a marker with base functionalities that add sub-level markers and
+ check if another marker exists as the parent itself or as its child.
+
+ Extends:
+ Marker
+ Properties:
+ name : The name of the marker.
+ children (list) : The list of all children (sub-level) markers.
+ Arguments:
+ name (str) : The name of the marker.
+ Methods:
+ getName : Returns the name of the marker.
+ addChild : Adds a sub-level marker.
+ addChilds : Adds a list of sub-level markers.
+ removeChild : Removes a specified sub-level marker.
+ contains : Checks if a sub-level marker exists.
+ """
+
+ @property
+ def name(self):
+ # type: () -> str
+ """Name of the parent marker."""
+ return self.__name
+
+ @property
+ def children(self):
+ # type: () -> List[Marker]
+ """Child markers of one parent marker."""
+ return self.__childs
+
+ @name.setter
+ def name(self, value):
+ # type: (str) -> None
+ self.__name = value
+
+ @children.setter
+ def children(self, value):
+ # type: (List[Marker]) -> None
+ self.__childs = value
+
+ def __init__(self, name): # type: (str)
+ """
+ Raises:
+ TypeError : If the `name` parameter is not a string.
+ ValueError : If the `name` parameter is an empty string.
+ """
- def __init__(self, name):
super(BaseMarker, self).__init__()
+
if not isinstance(name, str):
raise TypeError("not str type")
+
if name == "":
raise ValueError("empty value")
+
+ warn("Attribute `__childs` is replaced by the property `children`."
+ "Use children instead.", DeprecationWarning)
+
self.__name = name
self.__childs = []
- def getName(self):
- return self.__name
+ def add_child(self, marker):
+ # type: (Marker) -> None
+ """Append a marker to child markers.
- def __iter__(self):
- return iter(self.__childs)
+ Use this method to describe a different level of logs. For example,
+ error log would use the ERROR marker. However it's possible to
+ create a, for instance, TYPE_ERROR to mark type related events.
+ In this case TYPE_ERROR will be a child of parent ERROR.
- def __eq__(self, other):
+ Args:
+ marker : marker describing a different log level.
+ Raises:
+ TypeError : if the marker object has different type.
+ """
- if not isinstance(other, Marker):
- return False
- if id(self) == id(other):
- return True
+ if not isinstance(marker, Marker):
+ raise TypeError("Bad marker type. \
+ Can only add markers of type Marker. \
+ Type %s was passed." % type(marker))
- return self.__name == other.getName()
+ if self == marker:
+ return
- def __hash__(self):
- return hash(self.__name)
+ if marker not in self.children:
+ self.children.append(marker)
- def contains(self, item=None):
+ def add_children(self, markers):
+ # type: (Iterable[List]) -> None
+ """ Append a list of markers to child markers.
+
+ Args:
+ markers : An iterable object, containing markers.
+ Raises:
+ Exception : If `marker` parameter is not iterable.
+ """
+
+ try:
+ iter(markers)
+ except Exception as e:
+ raise e
+
+ for marker in markers:
+ self.children.append(marker)
+
+ def remove_child(self, marker):
+ # type: (Marker) -> None
+ """Use this method to remove a marker from the children list.
- if isinstance(item, Marker):
- if item == self:
+ Args:
+ marker : A child marker object.
+ Raises:
+ TypeError: if the marker object has different type.
+ """
+
+ if not isinstance(marker, Marker):
+ raise TypeError("Bad marker type. \
+ Can only add markers of type Marker. \
+ Type %s was passed." % type(marker))
+
+ if marker in self.children:
+ self.children.remove(marker)
+
+ def contains(self, item=None):
+ # type: (Optional[Union[Marker, str]]) -> bool
+ """
+ Use it to check if a marker exists as a parent itself or its chidren.
+
+ Args:
+ item : A child marker object. Defaults to None.
+ Returns:
+ bool : True if the marker exists.
+ """
+
+ warn("`item` argument will be replaced with `marker`. "
+ "Default value None will be removed.",
+ DeprecationWarning)
+ marker = item
+
+ if isinstance(marker, Marker):
+ if marker == self:
return True
return len(list(filter(
- lambda x: x == item, self.__childs))) > 0
+ lambda x: x == marker, self.children))) > 0
- elif isinstance(item, str):
- if item == self.__name:
+ elif isinstance(marker, str):
+ if marker == self.name:
return True
return len(list(filter(
- lambda x: x.__name == item, self.__childs))) > 0
+ lambda x: x.name == marker, self.children))) > 0
return False
- def addChild(self, item):
- if not isinstance(item, Marker):
- raise TypeError("can only add (not %s) marker type"
- % type(item))
- if self == item:
- return
- if item not in self.__childs:
- self.__childs.append(item)
+ def __iter__(self):
+ # type: () -> Iterator[List[Marker]]
+ return iter(self.__childs)
+
+ def __hash__(self):
+ # type (): -> int
+ return hash(self.__name)
+ def __eq__(self, other):
+ # type: (Marker) -> bool
+ if not isinstance(other, Marker):
+ return False
+ if id(self) == id(other):
+ return True
+
+ return self.__name == other.getName()
+
+ @deprecated(reason="Will be removed. Call the `name` property instead.")
+ def getName(self):
+ """Class attribute getter."""
+ return self.name
+
+ @deprecated(reason="Will be removed. Call add_children(markers) instead.")
def addChilds(self, childs):
- try:
- iter(childs)
- except Exception as e:
- raise e
+ """Add a list of sub-level markers. See add_children(markers)"""
+ self.add_children(childs)
- for item in childs:
- self.addChild(item)
+ @deprecated(reason="Will be removed. Call add_child(marker) instead.")
+ def addChild(self, item):
+ """Add a sub-level marker. See add_child(marker)"""
+ self.add_child(item)
+ @deprecated(reason="Will be removed. Call remove_child(marker) instead.")
def removeChild(self, item):
- if not isinstance(item, Marker):
- raise TypeError("can only add (not %s) marker type"
- % type(item))
- if item in self.__childs:
- self.__childs.remove(item)
+ """Remove a sub-level marker. See remove_child(marker)"""
+ self.remove_child(item)
+@deprecated(reason="Will be removed. "
+ "Call match_marker(record, marker_to_match) instead.")
def matchMarkerHelp(record, markerToMatch):
-
- marker = getattr(record, MARKER_TAG, None)
-
- if marker is None or markerToMatch is None:
+ """See match_marker(record, marker_to_match)."""
+ return match_markers(record, markerToMatch)
+
+
+def match_markers(record, marker_to_match):
+ # type: (LogRecord, Union[Marker, List]) -> bool
+ """
+ Use this method to match a marker (or a list of markers) with a LogRecord
+ record.
+
+ Args:
+ record : a record that may contain a marker.
+ markerToMatch : a marker or a list of markers.
+ Raises:
+ Exception : if match check went wrong.
+ Returns:
+ bool : whether the check can be done or the marker is found.
+ """
+ record_marker = getattr(record, MARKER_TAG, None)
+
+ if record_marker is None or \
+ marker_to_match is None:
return False
- if not isinstance(marker, Marker):
+ if not isinstance(record_marker, Marker):
return False
try:
- if isinstance(markerToMatch, list):
+ if isinstance(marker_to_match, list):
return len(list(filter(
- lambda x: marker.contains(x), markerToMatch))) > 0
+ lambda x: record_marker.contains(x), marker_to_match))) > 0
- return marker.contains(markerToMatch)
+ return record_marker.contains(marker_to_match)
except Exception as e:
raise e
diff --git a/pylog/onaplogging/marker/markerFactory.py b/pylog/onaplogging/marker/markerFactory.py
index 0705235..a0e9887 100644
--- a/pylog/onaplogging/marker/markerFactory.py
+++ b/pylog/onaplogging/marker/markerFactory.py
@@ -14,12 +14,32 @@
import abc
import threading
+
+from deprecated import deprecated
+from warnings import warn
+from typing import Dict, Optional
+
+from .marker import Marker
from .marker import BaseMarker
lock = threading.RLock()
class IMarkerFactory(object):
+ """Abstract marker factory for defining structure.
+
+ TODO:
+ after deprecated child methods are removed, rename them here.
+ Extends:
+ object
+ Method list:
+ getMarker
+ deleteMarker
+ exist
+ Raises:
+ NotImplementedError
+ """
+
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
@@ -36,39 +56,111 @@ class IMarkerFactory(object):
class MarkerFactory(IMarkerFactory):
+ """A factory class maganing every marker.
+
+ It is designed to check the existance, create and remove single markers.
+ This class follows a singleton pattern - only one instance can be created.
+
+ Extends:
+ IMarkerFactory
+ Properties:
+ marker_map : a map of existing markers.
+ Attributes:
+ _instance : a marker factory instance.
+ Methods:
+ getMarker : creates a new marker or returns an available one.
+ deleteMarker : removes a specific marker.
+ exist : checks if a specific marker exists.
+ """
_instance = None
_marker_map = {}
- def __new__(cls, *args, **kwargs):
-
- if cls._instance is None:
- cls._instance = super(MarkerFactory, cls).__new__(cls)
+ @property
+ def marker_map(self):
+ # type: () -> Dict
+ if not hasattr(self, '_marker_map'):
+ self._marker_map = {}
+ return self._marker_map
+
+ def get_marker(self, name=None):
+ # type: (Optional[str]) -> Marker
+ """
+ Use it to get any marker by its name. If it doesn't exist - it
+ will create a new marker that will be added to the factory.
+ Blocks the thread while executing.
+
+ Args:
+ name : A marker name. Defaults to None.
+ Raises:
+ ValueError : If `name` is None.
+ Returns:
+ Marker : A found or just newly created marker.
+ """
+
+ if name is None:
+ raise ValueError("Marker name is None. Must have a str value.")
- return cls._instance
+ lock.acquire()
- def getMarker(self, marker_name=None):
- if marker_name is None:
- raise ValueError("not empty")
+ marker = self.marker_map.get(name, None)
- lock.acquire()
- marker = self._marker_map.get(marker_name, None)
if marker is None:
- marker = BaseMarker(name=marker_name)
- self._marker_map[marker_name] = marker
+ marker = BaseMarker(name)
+ self.marker_map[name] = marker
+
lock.release()
return marker
- def deleteMarker(self, marker_name=None):
+ def delete_marker(self, name=None):
+ # type: (Optional[str]) -> bool
+ """
+ Args:
+ name: A marker name. Defaults to None.
+ Returns:
+ bool: The status of deletion.
+ """
+
lock.acquire()
- if self.exist(marker_name):
- del self._marker_map[marker_name]
+ exists = self.exists(name)
+ if exists:
+ del self.marker_map[name]
return True
lock.release()
+
return False
+ def exists(self, name=None):
+ # type: (Optional[str]) -> bool
+ """
+ Checks whether the search for a marker returns None and returns the
+ status of the operation.
+
+ Args:
+ name: marker name. Defaults to None.
+ Returns:
+ bool: status of whether the marker was found.
+ """
+ marker = self.marker_map.get(name, None)
+ return marker is not None
+
+ def __new__(cls, *args, **kwargs):
+ if cls._instance is None:
+ cls._instance = super(MarkerFactory, cls).__new__(cls)
+
+ warn("_marker_map attribute will be replaced by marker_map property.",
+ DeprecationWarning)
+ return cls._instance
+
+ @deprecated(reason="Will be removed. Call exists(name) instead.")
def exist(self, marker_name=None):
+ return self.exists(marker_name)
- return self._marker_map.get(
- marker_name, None) is not None
+ @deprecated(reason="Will be removed. Call get_marker(name) instead.")
+ def getMarker(self, marker_name=None):
+ return self.get_marker(marker_name)
+
+ @deprecated(reason="Will be removed. Call delete_marker(name) instead.")
+ def deleteMarker(self, marker_name=None):
+ return self.delete_marker(marker_name)
diff --git a/pylog/onaplogging/marker/markerFilter.py b/pylog/onaplogging/marker/markerFilter.py
index 4f49884..a381d8e 100644
--- a/pylog/onaplogging/marker/markerFilter.py
+++ b/pylog/onaplogging/marker/markerFilter.py
@@ -12,21 +12,57 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys
-from logging import Filter
-from .marker import matchMarkerHelp
+from logging import Filter, LogRecord
+from warnings import warn
+from typing import List, Optional, Union
+
+from onaplogging.utils.system import is_above_python_2_7
+
+from .marker import match_markers, Marker
class MarkerFilter(Filter):
+ """Marker filtering.
+
+ Extends:
+ logging.Filter
+ Properties:
+ marker_to_match (Marker/list): a marker of list of markers.
+ Methods
+ filter: Filter records by the current filter marker(s).
+ """
+
+ @property
+ def markers_to_match(self):
+ # type: () -> Union[Marker, List[Marker]]
+ return self.markersToMatch # TODO renamed - deprecated
- def __init__(self, name="", markers=None):
- if sys.version_info > (2, 7):
+ @markers_to_match.setter
+ def markers_to_match(self, value):
+ # type: ( Union[Marker, List[Marker]] ) -> None
+ self.markersToMatch = value
+
+ def __init__(self,
+ name="", # type: str
+ markers=None): # type: Optional[Union[Marker, List[Marker]]]
+
+ if is_above_python_2_7():
super(MarkerFilter, self).__init__(name)
+
else:
Filter.__init__(self, name)
- self.markerToMatch = markers
+ warn("markersToMatch attribute will be replaced by a property. "
+ "Use markers_to_match property instead.", DeprecationWarning)
+ self.markers_to_match = markers
def filter(self, record):
- # compare filter's markers with record's marker
- return matchMarkerHelp(record, self.markerToMatch)
+ # type: (LogRecord) -> bool
+ """Filter by looking for a marker match.
+
+ Args:
+ record: A record to match with the filter(s).
+ Returns:
+ bool: Whether the record matched with the filter(s)
+ """
+ return match_markers(record, self.markers_to_match)
diff --git a/pylog/onaplogging/marker/markerHandler.py b/pylog/onaplogging/marker/markerHandler.py
index 12b5488..36934a8 100644
--- a/pylog/onaplogging/marker/markerHandler.py
+++ b/pylog/onaplogging/marker/markerHandler.py
@@ -12,40 +12,118 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys
+from logging import LogRecord
from logging.handlers import SMTPHandler
-from .marker import matchMarkerHelp
+from typing import Tuple, List, Optional, Union
+
+from onaplogging.utils.system import is_above_python_2_7, is_above_python_3_2
+
+from .marker import match_markers, Marker
class MarkerNotifyHandler(SMTPHandler):
+ """Handler for email notification.
+
+ Wraps logging.handler.SMTPHandler and extends it by sending only such
+ notifications which contain certain markers.
+
+ Extends:
+ SMTPHandler
+ Property:
+ markers: A marker or a list of markers.
+ Args:
+ mailhost: A (host, port) tuple.
+ fromaddr: The sender of the email notification.
+ toaddrs: Email notification recepient(s).
+ subject: Email subject.
+ credentials: A (username, password) tuple.
+ secure: For example (TLS). It is used when the
+ credentials are supplied.
+ timout: Default is 5.0 seconds. Python version 3.2+
+ markers: A marker or a list of markers.
+ """
+
+ @property
+ def markers(self):
+ # type: () -> Union[Marker, List[Marker]]
+ return self._markers
+
+ @markers.setter
+ def markers(self, value):
+ # type: ( Union[Marker, List[Marker]] ) - None
+ self._markers = value
+
+ def __init__(self,
+ mailhost, # type: Tuple
+ fromaddr, # type: str
+ toaddrs, # type: Union[List[str], str]
+ subject, # type: Tuple
+ credentials=None, # type: Tuple
+ secure=None, # type: Optional[Tuple]
+ timeout=5.0, # type: Optional[float]
+ markers=None # type: Optional[Union[Marker, List[Marker]]]
+ ):
+
+ if is_above_python_3_2():
+ super(MarkerNotifyHandler, self). \
+ __init__( # noqa: E122
+ mailhost,
+ fromaddr,
+ toaddrs,
+ subject,
+ credentials,
+ secure,
+ timeout)
+
+ elif is_above_python_2_7():
+ super(MarkerNotifyHandler, self). \
+ __init__( # noqa: E122
+ mailhost,
+ fromaddr,
+ toaddrs,
+ subject,
+ credentials,
+ secure)
- def __init__(self, mailhost, fromaddr, toaddrs, subject,
- credentials=None, secure=None, timeout=5.0, markers=None):
-
- if sys.version_info > (3, 2):
- super(MarkerNotifyHandler, self).__init__(
- mailhost, fromaddr, toaddrs, subject,
- credentials, secure, timeout)
- elif sys.version_info > (2, 7):
- super(MarkerNotifyHandler, self).__init__(
- mailhost, fromaddr, toaddrs, subject,
- credentials, secure)
else:
SMTPHandler.__init__(self,
- mailhost, fromaddr, toaddrs, subject,
- credentials, secure)
+ mailhost,
+ fromaddr,
+ toaddrs,
+ subject,
+ credentials,
+ secure)
self.markers = markers
def handle(self, record):
+ # type: (LogRecord) -> bool
+ """
+ Handle a LogRecord record. Send an email notification.
+ """
+ return self.send_notification(record)
+
+ def send_notification(self, record):
+ # type: (LogRecord) -> bool
+ """Email notification handler.
- if self.markers is None:
+ Matches the record with the specific markers set for email
+ notifications. Sends an email notification if that marker(s) matched.
+
+ Args:
+ record (LogRecord): A record that might contain a marker.
+ Returns:
+ bool: Whether a record was passed for emission (to be sent).
+ """
+
+ if hasattr(self, "markers") and \
+ self.markers is None:
return False
- if matchMarkerHelp(record, self.markers):
- if sys.version_info > (2, 7):
- return super(SMTPHandler, self).handle(record)
- else:
- return SMTPHandler.handle(self, record)
+ if match_markers(record, self.markers):
+
+ if is_above_python_2_7():
+ return super(MarkerNotifyHandler, self).handle(record)
+ return SMTPHandler.handle(self, record)
return False
diff --git a/pylog/onaplogging/markerFormatter.py b/pylog/onaplogging/markerFormatter.py
index a322e29..d0da695 100644
--- a/pylog/onaplogging/markerFormatter.py
+++ b/pylog/onaplogging/markerFormatter.py
@@ -12,57 +12,116 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys
import logging
-from .marker import MARKER_TAG
-from .marker import Marker
+from logging import LogRecord
+from typing import Optional
+
+from onaplogging.utils.styles import MARKER_OPTIONS
+from onaplogging.utils.system import is_above_python_2_7, is_above_python_3_2
+
+from .marker import Marker, MARKER_TAG
from .colorFormatter import BaseColorFormatter
class MarkerFormatter(BaseColorFormatter):
+ """Formats coloring styles based on a marker.
- def __init__(self, fmt=None, datefmt=None, colorfmt=None, style='%'):
+ If `fmt` is not supplied, the `style` is used.
- if sys.version_info > (3, 2):
- super(MarkerFormatter, self).__init__(
- fmt=fmt, datefmt=datefmt, colorfmt=colorfmt, style=style)
- elif sys.version_info > (2, 7):
- super(MarkerFormatter, self).__init__(
- fmt=fmt, datefmt=datefmt, colorfmt=colorfmt)
- else:
- BaseColorFormatter.__init__(self, fmt, datefmt, colorfmt)
+ Extends:
+ BaseColorFormatter
+ Properties:
+ marker_tag: a marker to be applied.
+ temp_fmt : keeps initial format to be reset to after formatting.
+ Args:
+ fmt : human-readable format. Defaults to None.
+ datefmt : ISO8601-like (or RFC 3339-like) format. Defaults to None.
+ colorfmt : color schemas for logging levels. Defaults to None.
+ style : '%', '{' or '$' formatting. Defaults to '%'.
+ Added in Python 3.2.
+ """
+
+ @property
+ def marker_tag(self):
+ # type: () -> str
+ return self._marker_tag
+
+ @property
+ def temp_fmt(self):
+ # type: () -> str
+ return self._temp_fmt
+
+ @marker_tag.setter
+ def marker_tag(self, value):
+ # type: (str) -> None
+ self._marker_tag = value
- self._marker_tag = "%(marker)s"
+ @temp_fmt.setter
+ def temp_fmt(self, value):
+ # type: (str) -> None
+ self._temp_fmt = value
- if self.style == "{":
- self._marker_tag = "{marker}"
- elif self.style == "$":
- self._marker_tag = "${marker}"
+ def __init__(self,
+ fmt=None, # type: Optional[str]
+ datefmt=None, # type: Optional[str]
+ colorfmt=None, # type: Optional[dict]
+ style='%'): # type: Optional[str]
- self._tmpFmt = self._fmt
+ if is_above_python_3_2():
+ super(MarkerFormatter, self).\
+ __init__(fmt=fmt, # noqa: E122
+ datefmt=datefmt,
+ colorfmt=colorfmt,
+ style=style) # added in Python 3.2+
+
+ elif is_above_python_2_7():
+ super(MarkerFormatter, self).\
+ __init__(fmt=fmt, # noqa: E122
+ datefmt=datefmt,
+ colorfmt=colorfmt)
+
+ else:
+ BaseColorFormatter.\
+ __init__(self, fmt, datefmt, colorfmt) # noqa: E122
+
+ self.marker_tag = MARKER_OPTIONS[self.style]
+ self.temp_fmt = self._fmt
def format(self, record):
+ # type: (LogRecord) -> str
+ """Marker formatter.
+
+ Use it to apply the marker from the LogRecord record to the formatter
+ string `fmt`.
+ Args:
+ record : an instance of a logged event.
+ Returns:
+ str : "colored" text (formatted text).
+ """
try:
- if self._fmt.find(self._marker_tag) != -1 \
- and hasattr(record, MARKER_TAG):
+
+ if self._fmt.find(self.marker_tag) != -1 and \
+ hasattr(record, MARKER_TAG):
marker = getattr(record, MARKER_TAG)
if isinstance(marker, Marker):
- self._fmt = self._fmt.replace(
- self._marker_tag, marker.getName())
- elif self._fmt.find(self._marker_tag) != -1 \
- and not hasattr(record, MARKER_TAG):
+ self._fmt = self._fmt.replace(self.marker_tag,
+ marker.name)
- self._fmt = self._fmt.replace(self._marker_tag, "")
+ elif self._fmt.find(self.marker_tag) != -1 and \
+ not hasattr(record, MARKER_TAG):
+ self._fmt = self._fmt.replace(self.marker_tag, "")
- if sys.version_info > (3, 2):
- self._style = logging._STYLES[self.style][0](self._fmt)
+ if is_above_python_3_2():
+ StylingClass = logging._STYLES[self.style][0]
+ self.style = StylingClass(self._fmt)
- if sys.version_info > (2, 7):
+ if is_above_python_2_7():
+ # includes Python 3.2+ style attribute
return super(MarkerFormatter, self).format(record)
else:
return BaseColorFormatter.format(self, record)
finally:
- self._fmt = self._tmpFmt
+ self._fmt = self.temp_fmt
diff --git a/pylog/onaplogging/markerLogAdaptor.py b/pylog/onaplogging/markerLogAdaptor.py
index e901758..2c1e5df 100644
--- a/pylog/onaplogging/markerLogAdaptor.py
+++ b/pylog/onaplogging/markerLogAdaptor.py
@@ -12,74 +12,173 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys
from logging import LoggerAdapter
from threading import RLock
from functools import wraps
-from .marker import MARKER_TAG
-from .marker import Marker
+from deprecated import deprecated
+from typing import Dict, Callable
+
+from onaplogging.utils.system import is_above_python_3_2
+
+from .marker import Marker, MARKER_TAG
from .mdcContext import _getmdcs
lock = RLock()
-def addMarker(func):
+def add_marker(func):
+ # type: ( Callable[[Marker, str], None] ) -> Callable[[Marker, str], None]
+ """Marker decorator.
+
+ Requests a blocking acquisition of the thread. Sets the marker
+ as the logger's marker and delegates a call to the underlying
+ logger with contextual information. Next it removes the marker
+ and releases the thread.
+
+ Args:
+ func : a method supplied with a logging marker.
+ Raises:
+ TypeError : the marker type is not `Marker`.
+ Exception : `extra` doesn't exist or MARKER_TAG is in `extra`.
+ Returns:
+ method: decorated method.
+ """
@wraps(func)
def wrapper(self, marker, msg, *args, **kwargs):
+ # type: (Marker, str) -> Callable[[Marker, str], None]
+
lock.acquire()
+
if not isinstance(marker, Marker):
- raise TypeError("not marker type %s"
- % type(marker))
+ raise TypeError("Passed a marker of type %s. \
+ Should have the type %s."
+ % type(marker), "Marker")
+
+ if self.extra and \
+ MARKER_TAG in self.extra:
+ raise Exception("Can't add 'marker' in extra - either extra \
+ exists or MARKER_TAG is alredy in extra")
- if self.extra and MARKER_TAG in self.extra:
- raise Exception("cann't add 'marker' in extra")
setattr(self.logger, MARKER_TAG, marker)
+
func(self, marker, msg, *args, **kwargs)
+
if hasattr(self.logger, MARKER_TAG):
delattr(self.logger, MARKER_TAG)
+
lock.release()
+
return wrapper
+@deprecated(reason="@addMarker is deprecated. Use @add_marker instead.")
+def addMarker(func):
+ """Decorator. See new decorator add_marker(func)."""
+ add_marker(func)
+
+
class MarkerLogAdaptor(LoggerAdapter):
+ """Contextual loggin adapter.
- def process(self, msg, kwargs):
+ Specifies contextual information in logging output. Takes a logger and a
+ dictionary-like object `extra` for providing contextual information.
+
+ An example of the extra contextual information:
+ extra = {'app_name':'Marker Logging'}
+
+ Extends:
+ logging.LoggerAdapter
+ """
- if sys.version_info > (3, 2):
+ def process(self, msg, kwargs):
+ # type: (str, Dict)
+ """Logging call processor.
+
+ Takes a logging message and keyword arguments to provide cotextual
+ information.
+
+ Args:
+ msg : Logging information.
+ kwargs : Contextual information.
+ Returns:
+ str : Logging message.
+ dict : modified (or not) contextual information.
+ """
+ if is_above_python_3_2():
kwargs['extra'] = _getmdcs(self.extra)
else:
kwargs['extra'] = self.extra
return msg, kwargs
- @addMarker
- def infoMarker(self, marker, msg, *args, **kwargs):
-
+ @add_marker
+ def info_marker(self, marker, msg, *args, **kwargs):
+ # type: (Marker, str) -> None
+ """Provide the logger with an informational call."""
self.info(msg, *args, **kwargs)
- @addMarker
- def debugMarker(self, marker, msg, *args, **kwargs):
-
+ @add_marker
+ def debug_marker(self, marker, msg, *args, **kwargs):
+ # type: (Marker, str) -> None
+ """Provide the logger with a debug call."""
self.debug(msg, *args, **kwargs)
- @addMarker
- def warningMarker(self, marker, msg, *args, **kwargs):
-
+ @add_marker
+ def warning_marker(self, marker, msg, *args, **kwargs):
+ # type: (Marker, str) -> None
+ """Provide the logger with a warning call."""
self.warning(msg, *args, **kwargs)
- @addMarker
- def errorMarker(self, marker, msg, *args, **kwargs):
-
+ @add_marker
+ def error_marker(self, marker, msg, *args, **kwargs):
+ # type: (Marker, str) -> None
+ """Provide the logger with an error call."""
self.error(msg, *args, **kwargs)
- @addMarker
- def exceptionMarker(self, marker, msg, *arg, **kwargs):
- self.exception(msg, *arg, **kwargs)
+ @add_marker
+ def exception_marker(self, marker, msg, *args, **kwargs):
+ # type: (Marker, str) -> None
+ """Provide the logger with an exceptional call."""
+ self.exception(msg, *args, **kwargs)
+
+ @add_marker
+ def critical_marker(self, marker, msg, *args, **kwargs):
+ # type: (Marker, str) -> None
+ """Provide the logger with a critical call."""
+ self.critical(msg, *args, **kwargs)
+
+ @add_marker
+ def log_marker(self, marker, level, msg, *args, **kwargs):
+ # type: (Marker, str) -> None
+ """Provide the logger with a log call."""
+ self.log(marker, level, msg, *args, **kwargs)
+
+ @deprecated(reason="infoMarker(...) is replaced with info_marker(...).")
+ def infoMarker(self, marker, msg, *args, **kwargs):
+ self.info_marker(marker, msg, *args, **kwargs)
+
+ @deprecated(reason="debugMarker(...) is replaced with debug_marker(...).")
+ def debugMarker(self, marker, msg, *args, **kwargs):
+ self.debug_marker(marker, msg, *args, **kwargs)
+
+ @deprecated(reason="warningMarker(...) replaced, use warning_marker(...).")
+ def warningMarker(self, marker, msg, *args, **kwargs):
+ self.warning_marker(marker, msg, *args, **kwargs)
+
+ @deprecated(reason="errorMarker(...) is replaced with error_marker(...).")
+ def errorMarker(self, marker, msg, *args, **kwargs):
+ self.error_marker(marker, msg, *args, **kwargs)
+
+ @deprecated(reason="exceptionMarker(...) replaced,"
+ " use exception_marker(...).")
+ def exceptionMarker(self, marker, msg, *args, **kwargs):
+ self.exception_marker(marker, msg, *args, **kwargs)
- @addMarker
- def criticalMarker(self, marker, msg, *arg, **kwargs):
- self.critical(msg, *arg, **kwargs)
+ @deprecated(reason="criticalMarker(...) is replaced, "
+ "use critical_marker(...).")
+ def criticalMarker(self, marker, msg, *args, **kwargs):
+ self.critical_marker(marker, msg, *args, **kwargs)
- @addMarker
- def logMarker(self, marker, level, msg, *arg, **kwargs):
- self.log(level, msg, *arg, **kwargs)
+ @deprecated(reason="logMarker(...) is replaced with info_marker(...).")
+ def logMarker(self, marker, level, msg, *args, **kwargs):
+ self.log_marker(marker, level, msg, *args, **kwargs)
diff --git a/pylog/onaplogging/mdcContext.py b/pylog/onaplogging/mdcContext.py
index fa94536..c1852b3 100644
--- a/pylog/onaplogging/mdcContext.py
+++ b/pylog/onaplogging/mdcContext.py
@@ -19,9 +19,16 @@ import os
import traceback
import sys
import functools
-from .marker import Marker
-from .marker import MARKER_TAG
+from deprecated import deprecated
+from typing import Dict, Optional, Any, Callable, List, Tuple
+from logging import LogRecord
+
+from onaplogging.utils.system import is_above_python_3_2
+
+from .marker import Marker, MARKER_TAG
+
+# TODO change to patch_logging_mdc after deprecated method is removed
__all__ = ['patch_loggingMDC', 'MDC']
_replace_func_name = ['info', 'critical', 'fatal', 'debug',
@@ -29,123 +36,186 @@ _replace_func_name = ['info', 'critical', 'fatal', 'debug',
'handle', 'findCaller']
-class MDCContext(threading.local):
+def fetchkeys(func): # type: Callable[[str, List, Dict], None]
+ # type: (...) -> Callable[[str, List, Dict], None]
+ """MDC decorator.
+
+ Fetchs contextual information from a logging call.
+ Wraps by adding MDC to the `extra` field. Executes
+ the call with the updated contextual information.
"""
- A Thread local instance to storage mdc values
+
+ @functools.wraps(func)
+ def replace(*args, **kwargs):
+ # type: () -> None
+ kwargs['extra'] = _getmdcs(extra=kwargs.get('extra', None))
+ func(*args, **kwargs)
+
+ return replace
+
+
+class MDCContext(threading.local):
+ """A Thread local instance that stores MDC values.
+
+ Is initializ with an empty dictionary. Manages that
+ dictionary to created Mapped Diagnostic Context.
+
+ Extends:
+ threading.local
+ Property:
+ local_dict : a placeholder for MDC keys and values.
"""
- def __init__(self):
+ @property
+ def local_dict(self):
+ # type: () -> Dict
+ return self._local_dict
+
+ @local_dict.setter
+ def local_dict(self, value):
+ # type: (Dict) -> None
+ self._local_dict = value
+
+ def __init__(self):
super(MDCContext, self).__init__()
- self._localDict = {}
+ self.local_dict = {}
def get(self, key):
-
- return self._localDict.get(key, None)
+ # type: (str) -> Any
+ """Retrieve a value by key."""
+ return self.local_dict.get(key, None)
def put(self, key, value):
-
- self._localDict[key] = value
+ # type: (str, Any) -> None
+ """Insert or update a value by key."""
+ self.local_dict[key] = value
def remove(self, key):
-
- if key in self.localDict:
- del self._localDict[key]
+ # type: (str) -> None
+ """Remove a value by key, if exists."""
+ if key in self.local_dict:
+ del self.local_dict[key]
def clear(self):
+ # type: () -> None
+ """Empty the MDC dictionary."""
+ self.local_dict.clear()
- self._localDict.clear()
-
+ @deprecated(reason="Use local_mdc property instead.")
def result(self):
+ """Getter for the MDC dictionary."""
+ return self.local_dict
- return self._localDict
+ def empty(self):
+ # type: () -> bool
+ """Checks whether the local dictionary is empty."""
+ return self.local_dict == {} or \
+ self.local_dict is None
+ @deprecated(reason="Will be replaced. Use empty() instead.")
def isEmpty(self):
-
- return self._localDict == {} or self._localDict is None
+ """See empty()."""
+ return self.empty()
MDC = MDCContext()
-def fetchkeys(func):
-
- @functools.wraps(func)
- def replace(*args, **kwargs):
- kwargs['extra'] = _getmdcs(extra=kwargs.get('extra', None))
- func(*args, **kwargs)
- return replace
-
-
def _getmdcs(extra=None):
+ # type: (Optional[Dict]) -> Dict
"""
- Put mdc dict in logging record extra filed with key 'mdc'
- :param extra: dict
- :return: mdc dict
+ Puts an MDC dict in the `extra` field with key 'mdc'. This provides
+ the contextual information with MDC.
+
+ Args:
+ extra : Contextual information. Defaults to None.
+ Raises:
+ KeyError : a key from extra is attempted to be overwritten.
+ Returns:
+ dict : contextual information named `extra` with MDC.
"""
- if MDC.isEmpty():
+ if MDC.empty():
return extra
- mdc = MDC.result()
+ mdc = MDC.local_dict
if extra is not None:
for key in extra:
- # make sure extra key dosen't override mdckey
- if key in mdc or key == 'mdc':
+ if key in mdc or \
+ key == 'mdc':
raise KeyError("Attempt to overwrite %r in MDC" % key)
else:
extra = {}
extra['mdc'] = mdc
-
del mdc
+
return extra
@fetchkeys
def info(self, msg, *args, **kwargs):
-
+ # type: (str) -> None
+ """If INFO enabled, deletage an info call with MDC."""
if self.isEnabledFor(logging.INFO):
self._log(logging.INFO, msg, args, **kwargs)
@fetchkeys
def debug(self, msg, *args, **kwargs):
+ # type: (str) -> None
+ """If DEBUG enabled, deletage a debug call with MDC."""
if self.isEnabledFor(logging.DEBUG):
self._log(logging.DEBUG, msg, args, **kwargs)
@fetchkeys
def warning(self, msg, *args, **kwargs):
+ # type: (str) -> None
+ """If WARNING enabled, deletage a warning call with MDC."""
if self.isEnabledFor(logging.WARNING):
self._log(logging.WARNING, msg, args, **kwargs)
@fetchkeys
def exception(self, msg, *args, **kwargs):
-
+ # type: (str) -> None
+ """Deletage an exception call and set exc_info code to 1."""
kwargs['exc_info'] = 1
self.error(msg, *args, **kwargs)
@fetchkeys
def critical(self, msg, *args, **kwargs):
-
+ # type: (str) -> None
+ """If CRITICAL enabled, deletage a critical call with MDC."""
if self.isEnabledFor(logging.CRITICAL):
self._log(logging.CRITICAL, msg, args, **kwargs)
@fetchkeys
def error(self, msg, *args, **kwargs):
+ # type: (str) -> None
+ """If ERROR enabled, deletage an error call with MDC."""
if self.isEnabledFor(logging.ERROR):
self._log(logging.ERROR, msg, args, **kwargs)
@fetchkeys
def log(self, level, msg, *args, **kwargs):
+ # type: (int, str) -> None
+ """
+ If a specific logging level enabled and the code is represented
+ as an integer value, delegate the call to the underlying logger.
+
+ Raises:
+ TypeError: if the logging level code is not an integer.
+ """
if not isinstance(level, int):
if logging.raiseExceptions:
- raise TypeError("level must be an integer")
+ raise TypeError("Logging level code must be an integer."
+ "Got %s instead." % type(level))
else:
return
@@ -154,55 +224,80 @@ def log(self, level, msg, *args, **kwargs):
def handle(self, record):
-
+ # type: (LogRecord) -> None
cmarker = getattr(self, MARKER_TAG, None)
if isinstance(cmarker, Marker):
setattr(record, MARKER_TAG, cmarker)
- if (not self.disabled) and self.filter(record):
+ if not self.disabled and \
+ self.filter(record):
self.callHandlers(record)
def findCaller(self, stack_info=False):
+ # type: (bool) -> Tuple
+ """
+ Find the stack frame of the caller so that we can note the source file
+ name, line number and function name. Enhances the logging.findCaller().
+ """
+
+ frame = logging.currentframe()
- f = logging.currentframe()
- if f is not None:
- f = f.f_back
+ if frame is not None:
+ frame = frame.f_back
rv = "(unkown file)", 0, "(unknow function)"
- while hasattr(f, "f_code"):
- co = f.f_code
+
+ while hasattr(frame, "f_code"):
+ co = frame.f_code
filename = os.path.normcase(co.co_filename)
# jump through local 'replace' func frame
- if filename == logging._srcfile or co.co_name == "replace":
- f = f.f_back
+ if filename == logging._srcfile or \
+ co.co_name == "replace":
+
+ frame = frame.f_back
continue
- if sys.version_info > (3, 2):
+
+ if is_above_python_3_2():
+
sinfo = None
if stack_info:
+
sio = io.StringIO()
sio.write("Stack (most recent call last):\n")
- traceback.print_stack(f, file=sio)
+ traceback.print_stack(frame, file=sio)
sinfo = sio.getvalue()
+
if sinfo[-1] == '\n':
sinfo = sinfo[:-1]
+
sio.close()
- rv = (co.co_filename, f.f_lineno, co.co_name, sinfo)
+ rv = (co.co_filename, frame.f_lineno, co.co_name, sinfo)
+
else:
- rv = (co.co_filename, f.f_lineno, co.co_name)
+ rv = (co.co_filename, frame.f_lineno, co.co_name)
break
return rv
-def patch_loggingMDC():
- """
- The patch to add MDC ability in logging Record instance at runtime
+def patch_logging_mdc():
+ # type: () -> None
+ """MDC patch.
+
+ Sets MDC in a logging record instance at runtime.
"""
localModule = sys.modules[__name__]
+
for attr in dir(logging.Logger):
if attr in _replace_func_name:
newfunc = getattr(localModule, attr, None)
if newfunc:
setattr(logging.Logger, attr, newfunc)
+
+
+@deprecated(reason="Will be removed. Call patch_logging_mdc() instead.")
+def patch_loggingMDC():
+ """See patch_logging_ymdc()."""
+ patch_logging_mdc()
diff --git a/pylog/onaplogging/mdcformatter.py b/pylog/onaplogging/mdcformatter.py
index 545a4c1..442f0ad 100644
--- a/pylog/onaplogging/mdcformatter.py
+++ b/pylog/onaplogging/mdcformatter.py
@@ -12,145 +12,214 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys
import logging
+from logging import LogRecord
+from typing import Mapping, List, Dict, Callable
+from deprecated import deprecated
+
+from onaplogging.utils.system import is_above_python_2_7, is_above_python_3_2
+from onaplogging.utils.styles import MDC_OPTIONS
+
from .markerFormatter import MarkerFormatter
class MDCFormatter(MarkerFormatter):
- """
- A custom MDC formatter to prepare Mapped Diagnostic Context
- to enrich log message.
+ """A custom MDC formatter.
+
+ Prepares Mapped Diagnostic Context to enrich log message. If `fmt` is not
+ supplied, the `style` is used.
+
+ Extends:
+ MarkerFormatter
+ Args:
+ fmt : Built-in format string containing standard Python
+ %-style mapping keys in human-readable format.
+ mdcFmt : MDC format with '{}'-style mapping keys.
+ datefmt : Date format.
+ colorfmt : colored output with an ANSI terminal escape code.
+ style : style mapping keys in Python 3.x.
"""
- def __init__(self, fmt=None, mdcfmt=None,
- datefmt=None, colorfmt=None, style="%"):
- """
- :param fmt: build-in format string contains standard
- Python %-style mapping keys
- :param mdcFmt: mdc format with '{}'-style mapping keys
- :param datefmt: Date format to use
- :param colorfmt: colored output with ANSI escape code on terminal
- :param style: style mapping keys in python3
- """
- if sys.version_info > (3, 2):
+ @property
+ def mdc_tag(self):
+ # type: () -> str
+ return self._mdc_tag
+
+ @property
+ def mdcfmt(self):
+ # type: () -> str
+ return self._mdcFmt
+
+ @mdc_tag.setter
+ def mdc_tag(self, value):
+ # type: (str) -> str
+ self._mdc_tag = value
+
+ @mdcfmt.setter
+ def mdcfmt(self, value):
+ # type: (str) -> str
+ self._mdc_tag = value
+
+ def __init__(self,
+ fmt=None, # type: str
+ mdcfmt=None, # type: str
+ datefmt=None, # type: str
+ colorfmt=None, # type: str
+ style="%"): # type: str
+
+ if is_above_python_3_2():
super(MDCFormatter, self).__init__(fmt=fmt,
datefmt=datefmt,
colorfmt=colorfmt,
style=style)
- elif sys.version_info > (2, 7):
+ elif is_above_python_2_7():
super(MDCFormatter, self).__init__(fmt=fmt,
datefmt=datefmt,
colorfmt=colorfmt)
else:
- MarkerFormatter.__init__(self, fmt, datefmt, colorfmt)
-
- self._mdc_tag = "%(mdc)s"
- if self.style == "{":
- self._mdc_tag = "{mdc}"
- elif self.style == "$":
- self._mdc_tag = "${mdc}"
+ MarkerFormatter.\
+ __init__(self, fmt, datefmt, colorfmt) # noqa: E122
- if mdcfmt:
- self._mdcFmt = mdcfmt
- else:
- self._mdcFmt = '{reqeustID}'
+ self._mdc_tag = MDC_OPTIONS[self.style]
+ self._mdcFmt = mdcfmt if mdcfmt else '{reqeustID}'
- def _mdcfmtKey(self):
+ def format(self, record):
+ # type: (LogRecord) -> str
"""
- maximum barce match algorithm to find the mdc key
- :return: key in brace and key not in brace,such as ({key}, key)
+ Find MDCs in a log record's extra field. If the key from mdcFmt
+ doesn't contain MDC, the values will be empty.
+
+ For example:
+ The MDC dict in a logging record is {'key1':'value1','key2':'value2'}.
+ The mdcFmt is '{key1} {key3}'.
+ The output of MDC message is 'key1=value1 key3='.
+
+ Args:
+ record : an instance of a logged event.
+ Returns:
+ str : "colored" text (formatted text).
+ """
+
+ mdc_index = self._fmt.find(self._mdc_tag)
+ if mdc_index == -1:
+ return self._parent_format(record)
+
+ mdc_format_keys, mdc_format_words = self._mdc_format_key()
+
+ if mdc_format_words is None:
+ self._fmt = self._replace_mdc_tag_str("")
+ self._apply_styling()
+
+ return self._parent_format(record)
+
+ res = self._apply_mdc(record, mdc_format_words)
+
+ try:
+ mdc_string = self._replaceStr(keys=mdc_format_keys).format(**res)
+ self._fmt = self._replace_mdc_tag_str(mdc_string)
+ self._apply_styling()
+
+ return self._parent_format(record)
+
+ except KeyError as e:
+ # is there a need for print?
+ print("The mdc key %s format is wrong" % str(e))
+
+ except Exception:
+ raise
+
+ def _mdc_format_key(self):
+ # type: () -> (List, Mapping[str, str])
+ """Maximum (balanced) parantehses matching algorithm for MDC keys.
+
+ Extracts and strips keys and words from a MDC format string. Use this
+ method to find the MDC key.
+
+ Returns:
+ list : list of keys.
+ map object : keys with and without brace, such as ({key}, key).
"""
left = '{'
right = '}'
target = self._mdcFmt
- st = []
+ stack = []
keys = []
+
for index, v in enumerate(target):
if v == left:
- st.append(index)
+ stack.append(index)
elif v == right:
- if len(st) == 0:
+ if len(stack) == 0:
continue
- elif len(st) == 1:
- start = st.pop()
+ elif len(stack) == 1:
+ start = stack.pop()
end = index
keys.append(target[start:end + 1])
- elif len(st) > 0:
- st.pop()
+ elif len(stack) > 0:
+ stack.pop()
keys = list(filter(lambda x: x[1:-1].strip('\n \t ') != "", keys))
words = None
+
if keys:
words = map(lambda x: x[1:-1], keys)
return keys, words
- def _replaceStr(self, keys):
-
- fmt = self._mdcFmt
- for i in keys:
- fmt = fmt.replace(i, i[1:-1] + "=" + i)
-
- return fmt
-
- def format(self, record):
+ def _replace_string(self, keys):
+ # type: (List[str]) -> str
"""
- Find mdcs in log record extra field, if key form mdcFmt dosen't
- contains mdcs, the values will be empty.
- :param record: the logging record instance
- :return: string
- for example:
- the mdcs dict in logging record is
- {'key1':'value1','key2':'value2'}
- the mdcFmt is" '{key1} {key3}'
- the output of mdc message: 'key1=value1 key3='
-
+ Removes the first and last characters from each key and assigns not
+ stripped keys.
"""
- mdcIndex = self._fmt.find(self._mdc_tag)
- if mdcIndex == -1:
- if sys.version_info > (2, 7):
- return super(MDCFormatter, self).format(record)
- else:
- return MarkerFormatter.format(self, record)
-
- mdcFmtkeys, mdcFmtWords = self._mdcfmtKey()
-
- if mdcFmtWords is None:
- self._fmt = self._fmt.replace(self._mdc_tag, "")
- if sys.version_info > (3, 2):
- self._style = logging._STYLES[self.style][0](self._fmt)
+ fmt = self._mdcFmt
+ for key in keys:
+ fmt = fmt.replace(key, key[1:-1] + "=" + key)
+ return fmt
- if sys.version_info > (2, 7):
- return super(MDCFormatter, self).format(record)
- else:
- return MarkerFormatter.format(self, record)
+ def _parent_format(self, record):
+ # type: (LogRecord) -> str
+ """Call super class's format based on Python version."""
+ if is_above_python_2_7():
+ return super(MDCFormatter, self).format(record)
+ else:
+ return MarkerFormatter.format(self, record)
+ def _apply_mdc(self, record, mdc_format_words):
+ # type: (LogRecord, Mapping[Callable[[str], str], List]) -> Dict
+ """Apply MDC pamming to the LogRecord record."""
mdc = record.__dict__.get('mdc', None)
res = {}
- for i in mdcFmtWords:
+
+ for i in mdc_format_words:
if mdc and i in mdc:
res[i] = mdc[i]
else:
res[i] = ""
-
del mdc
- try:
- mdcstr = self._replaceStr(keys=mdcFmtkeys).format(**res)
- self._fmt = self._fmt.replace(self._mdc_tag, mdcstr)
+ return res
- if sys.version_info > (3, 2):
- self._style = logging._STYLES[self.style][0](self._fmt)
+ def _apply_styling(self):
+ # type: () -> None
+ """Apply styling to the formatter if using Python 3.2+"""
+ if is_above_python_3_2():
+ StylingClass = logging._STYLES[self.style][0](self._fmt)
+ self._style = StylingClass
- if sys.version_info > (2, 7):
- return super(MDCFormatter, self).format(record)
- else:
- return MarkerFormatter.format(self, record)
+ def _replace_mdc_tag_str(self, replacement):
+ # type: (str) -> str
+ """Replace MDC tag in the format string."""
+ return self._fmt.replace(self._mdc_tag, replacement)
- except KeyError as e:
- print("The mdc key %s format is wrong" % str(e))
- except Exception:
- raise
+ @deprecated(reason="Will be replaced. Use _mdc_format_key() instead.")
+ def _mdcfmtKey(self):
+ """See _mdc_format_key()."""
+ return self._mdc_format_key()
+
+ @deprecated(reason="Will be replaced. Use _replace_string(keys) instead.")
+ def _replaceStr(self, keys):
+ """See _replace_string(keys)."""
+ return self._replace_string(keys)
diff --git a/pylog/onaplogging/monkey.py b/pylog/onaplogging/monkey.py
index f8bf992..33c3ced 100644
--- a/pylog/onaplogging/monkey.py
+++ b/pylog/onaplogging/monkey.py
@@ -12,17 +12,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from .mdcContext import patch_loggingMDC
-from .logWatchDog import patch_loggingYaml
+from typing import Optional
+
+from .mdcContext import patch_logging_mdc
+from .logWatchDog import patch_logging_yaml
__all__ = ["patch_all"]
def patch_all(mdc=True, yaml=True):
+ # type: ( Optional[bool], Optional[bool] ) -> None
+ """
+ Patches both MDC contextual information and YAML configuration file to the
+ logger by default. To exclude any or both set `mdc` and/or `yaml`
+ parameters to False.
+
+ Args:
+ mdc (bool, optional): Defaults to True.
+ yaml (bool, optional): Defaults to True.
+ """
if mdc is True:
- patch_loggingMDC()
+ patch_logging_mdc()
if yaml is True:
- patch_loggingYaml()
+ patch_logging_yaml()
diff --git a/pylog/onaplogging/utils/__init__.py b/pylog/onaplogging/utils/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/pylog/onaplogging/utils/__init__.py
diff --git a/pylog/onaplogging/utils/styles.py b/pylog/onaplogging/utils/styles.py
new file mode 100644
index 0000000..e445aee
--- /dev/null
+++ b/pylog/onaplogging/utils/styles.py
@@ -0,0 +1,84 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+"""These are ANSI shell coloring codes used to format strings.
+
+[ begins the color definition. \033 starts the escape sequence.
+[\0330m is the default color of the shell that closes the escape sequence.
+
+`FMT_STR` takes the color as its first parameter (int). As the second
+parameter its takes the text (str).
+
+TL;DR
+ Examples on ANSI colors, attributes, backgrounds and foregrounds:
+ https://stackoverflow.com/a/28938235/7619961
+"""
+
+COLOR_TAG = "color"
+HIGHLIGHT_TAG = "highlight"
+ATTRIBUTE_TAG = "attribute"
+
+RESET = "\033[0m"
+FMT_STR = "\033[%dm%s"
+
+ATTRIBUTES = {
+
+ 'normal': 0,
+ 'bold': 1,
+ 'underline': 4,
+ 'blink': 5,
+ 'invert': 7,
+ 'hide': 8,
+
+}
+
+HIGHLIGHTS = {
+
+ 'black': 40,
+ 'red': 41,
+ 'green': 42,
+ 'yellow': 43,
+ 'blue': 44,
+ 'purple': 45,
+ 'cyan': 46,
+ 'white': 47,
+
+}
+
+COLORS = {
+
+ 'black': 30,
+ 'red': 31,
+ 'green': 32,
+ 'yellow': 33,
+ 'blue': 34,
+ 'purple': 35,
+ 'cyan': 36,
+ 'white': 37,
+
+}
+
+"""
+MDC and MARKER options are used only with Python starting 3.2 due to an update
+in the logging module. This allows the use of %-formatting, :meth:`str.format`
+(``{}``) formatting or :class:`string.Template` in the format string.
+"""
+
+MARKER_OPTIONS = {
+ "%": "%(marker)s",
+ "{": "{marker}",
+ "$": "${marker}"
+}
+
+MDC_OPTIONS = {
+ "%": "%(mdc)s",
+ "{": "{mdc}",
+ "$": "${mdc}"
+}
diff --git a/pylog/onaplogging/utils/system.py b/pylog/onaplogging/utils/system.py
new file mode 100644
index 0000000..cfe49a1
--- /dev/null
+++ b/pylog/onaplogging/utils/system.py
@@ -0,0 +1,31 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+import sys
+
+
+def is_above_python_3_2():
+ # type: () -> bool
+ """Check if code is running at least on Python 3.2 version.
+
+ Returns:
+ bool: True if it's at least 3.2 version, False otherwise
+ """
+ return sys.version_info >= (3, 2, 0, "final", 0)
+
+
+def is_above_python_2_7():
+ # type: () -> bool
+ """Check if code is running at least on Python 2.7 version.
+
+ Returns:
+ bool: True if it's at least 2.7 version, False otherwise
+ """
+ return sys.version_info >= (2, 7, 0, "final", 0)
diff --git a/pylog/onaplogging/utils/tools.py b/pylog/onaplogging/utils/tools.py
new file mode 100644
index 0000000..0cb0129
--- /dev/null
+++ b/pylog/onaplogging/utils/tools.py
@@ -0,0 +1,32 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+import yaml
+
+from deprecated import deprecated
+
+
+def yaml_to_dict(filepath):
+ # type: (str) -> dict
+ """YAML to Python dict converter.
+
+ Args:
+ filepath : The filepath to a YAML file.
+ Returns:
+ dict : Python dictionary object.
+ """
+ with open(filepath, 'rt') as f:
+ return yaml.load(f.read())
+
+
+@deprecated(reason="Will be removed. Call yaml_to_dict(filepath) instead.")
+def _yaml2Dict(filename):
+ """YAML to dict. See yaml_to_dict(filepath)."""
+ return yaml_to_dict(filename)
diff --git a/pylog/pom.xml b/pylog/pom.xml
index f68151a..a8a6606 100644
--- a/pylog/pom.xml
+++ b/pylog/pom.xml
@@ -11,21 +11,21 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-->
-<project
- xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
<parent>
- <groupId>org.onap.oparent</groupId>
- <artifactId>oparent</artifactId>
- <version>2.0.0</version>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-analytics</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
</parent>
- <groupId>org.onap.logging-analytics</groupId>
- <modelVersion>4.0.0</modelVersion>
+
<artifactId>logging-pylog</artifactId>
- <version>1.6.1</version>
<packaging>pom</packaging>
- <name>logging-pylog</name>
+
+ <name>logging-analytics :: ${project.artifactId}</name>
<description>onap python logging library</description>
+
<build>
<plugins>
<plugin>
diff --git a/pylog/requirements.txt b/pylog/requirements.txt
index 16afb32..be12b1b 100644
--- a/pylog/requirements.txt
+++ b/pylog/requirements.txt
@@ -1,2 +1,4 @@
PyYAML
watchdog
+deprecated
+typing
diff --git a/pylog/setup.py b/pylog/setup.py
index 99669fd..d0bb0e0 100644
--- a/pylog/setup.py
+++ b/pylog/setup.py
@@ -21,7 +21,7 @@ setup(
long_description="python-package onappylog could be used in any python"
"project to record MDC information and reload logging"
"at runtime",
- version="1.0.7",
+ version="1.6.10",
license="Apache 2.0",
author='ke liang',
author_email="lokyse@163.com",
diff --git a/pylog/test_requirements.txt b/pylog/test_requirements.txt
new file mode 100644
index 0000000..a5c4199
--- /dev/null
+++ b/pylog/test_requirements.txt
@@ -0,0 +1,5 @@
+-r requirements.txt
+pytest
+mock
+deprecated
+typing \ No newline at end of file
diff --git a/pylog/tests/test_color_formatter.py b/pylog/tests/test_color_formatter.py
new file mode 100644
index 0000000..56bf9c2
--- /dev/null
+++ b/pylog/tests/test_color_formatter.py
@@ -0,0 +1,133 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+import unittest
+import sys
+from logging import LogRecord
+
+if sys.version_info[0] < 3:
+ from mock import patch
+if sys.version_info[0] >= 3:
+ from unittest.mock import patch
+import pytest
+
+from onaplogging.colorFormatter import (
+ ATTRIBUTES,
+ BaseColorFormatter,
+ colored,
+ COLORS,
+ HIGHLIGHTS,
+ FMT_STR,
+ RESET,
+)
+from onaplogging.utils.system import is_above_python_3_2
+
+
+class TestColorFormatter(unittest.TestCase):
+
+ TEST_TEXT = "test"
+
+ def test_colored_os_name_nt(self):
+
+ with patch("onaplogging.colorFormatter.os.name", "nt"):
+
+ text = colored(self.TEST_TEXT)
+ assert text == self.TEST_TEXT
+
+ text = colored(self.TEST_TEXT, color="black")
+ assert text == self.TEST_TEXT
+
+ text = colored(self.TEST_TEXT, on_color="black")
+ assert text == self.TEST_TEXT
+
+ text = colored(self.TEST_TEXT, attrs="bold")
+ assert text == self.TEST_TEXT
+
+ def test_colored_os_name_ce(self):
+
+ with patch("onaplogging.colorFormatter.os.name", "ce"):
+
+ text = colored(self.TEST_TEXT)
+ assert text == self.TEST_TEXT
+
+ text = colored(self.TEST_TEXT, color="black")
+ assert text == self.TEST_TEXT
+
+ text = colored(self.TEST_TEXT, on_color="black")
+ assert text == self.TEST_TEXT
+
+ text = colored(self.TEST_TEXT, attrs="bold")
+ assert text == self.TEST_TEXT
+
+ def test_colored_os_name_posix(self):
+
+ with patch("onaplogging.colorFormatter.os.name", "posix"):
+ text = colored(self.TEST_TEXT)
+ assert text == self.TEST_TEXT + RESET
+
+ text = colored(self.TEST_TEXT, color="black")
+ assert text == FMT_STR % (COLORS["black"], self.TEST_TEXT) + RESET
+
+ text = colored(self.TEST_TEXT, color="invalid")
+ assert text == FMT_STR % (0, self.TEST_TEXT) + RESET
+
+ text = colored(self.TEST_TEXT, on_color="red")
+ assert text == FMT_STR % (HIGHLIGHTS["red"], self.TEST_TEXT) + RESET
+
+ text = colored(self.TEST_TEXT, on_color="invalid")
+ assert text == FMT_STR % (0, self.TEST_TEXT) + RESET
+
+ text = colored(self.TEST_TEXT, attrs="bold")
+ assert text == FMT_STR % (ATTRIBUTES["bold"], self.TEST_TEXT) + RESET
+
+ text = colored(self.TEST_TEXT, attrs=["bold", "blink"])
+ assert (
+ text
+ == FMT_STR % (ATTRIBUTES["blink"], FMT_STR % (ATTRIBUTES["bold"], self.TEST_TEXT))
+ + RESET
+ )
+
+ text = colored(self.TEST_TEXT, attrs="invalid")
+ assert text == FMT_STR % (0, self.TEST_TEXT) + RESET
+
+ def test_base_color_formatter(self):
+
+ if is_above_python_3_2():
+ with pytest.raises(ValueError):
+ BaseColorFormatter(style="!")
+
+ TEST_MESSAGE = "TestMessage"
+ record = LogRecord(
+ name="TestName",
+ level=0,
+ pathname="TestPathName",
+ lineno=1,
+ msg=TEST_MESSAGE,
+ args=None,
+ exc_info=None,
+ )
+
+ base_formatter = BaseColorFormatter()
+ assert base_formatter.format(record) == TEST_MESSAGE + RESET
+
+ base_formatter = BaseColorFormatter(fmt="TEST %(message)s")
+ assert base_formatter.format(record) == "TEST " + TEST_MESSAGE + RESET
+
+ colorfmt = {record.levelname: {"color": "black", "highlight": "red", "attribute": "bold"}}
+ base_formatter = BaseColorFormatter(colorfmt=colorfmt)
+ assert (
+ base_formatter.format(record)
+ == FMT_STR
+ % (
+ ATTRIBUTES["bold"],
+ FMT_STR % (HIGHLIGHTS["red"], FMT_STR % (COLORS["black"], "TestMessage")),
+ )
+ + RESET
+ )
diff --git a/pylog/tests/test_example.py b/pylog/tests/test_example.py
deleted file mode 100644
index c0d97bf..0000000
--- a/pylog/tests/test_example.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright (c) 2018-2019 VMware, 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.
-
-
-import unittest
-
-
-class TestExample(unittest.TestCase):
-
- def test_mdcFormat(self):
- return
diff --git a/pylog/tests/test_log_watchdog.py b/pylog/tests/test_log_watchdog.py
new file mode 100644
index 0000000..e1b9fea
--- /dev/null
+++ b/pylog/tests/test_log_watchdog.py
@@ -0,0 +1,91 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+import os
+import sys
+import unittest
+from collections import namedtuple
+from tempfile import NamedTemporaryFile
+
+if sys.version_info[0] < 3:
+ from mock import patch
+if sys.version_info[0] >= 3:
+ from unittest.mock import patch
+
+import pytest
+import yaml
+
+from onaplogging.logWatchDog import FileEventHandlers, _yamlConfig
+from onaplogging.utils.tools import yaml_to_dict, _yaml2Dict
+
+
+TestEvent = namedtuple("TestEvent", ["src_path"])
+
+
+class TestLogWatchdog(unittest.TestCase):
+
+ TEST_DICT = {
+ "A": {
+ "B": "C"
+ }
+ }
+
+ def setUp(self):
+ super(TestLogWatchdog, self).setUp()
+
+ self.temp_file = NamedTemporaryFile(mode="w+t", delete=False)
+ self.temp_file.write(yaml.dump(self.TEST_DICT))
+ self.temp_file.close()
+
+ def tearDown(self):
+ super(TestLogWatchdog, self).tearDown()
+
+ os.unlink(self.temp_file.name)
+
+ def test_yaml2dict(self):
+ with pytest.raises(TypeError):
+ _yaml2Dict(None)
+
+ self.assertDictEqual(self.TEST_DICT, _yaml2Dict(self.temp_file.name))
+
+ def test_file_event_handler(self):
+
+ with patch("onaplogging.logWatchDog.config.dictConfig") as mock_config:
+ mock_config.side_effect = Exception
+
+ feh = FileEventHandlers(self.temp_file.name)
+ self.assertIsNone(feh.currentConfig)
+ feh.on_modified(TestEvent(src_path=self.temp_file.name))
+ self.assertIsNone(feh.currentConfig)
+
+ with patch("onaplogging.logWatchDog.config"):
+
+ feh = FileEventHandlers(self.temp_file.name)
+ self.assertIsNone(feh.currentConfig)
+ feh.on_modified(TestEvent(src_path=self.temp_file.name))
+ self.assertIsNotNone(feh.currentConfig)
+
+ def test_patch_yaml_config(self):
+
+ with pytest.raises(TypeError):
+ _yamlConfig(filepath=None)
+
+ with pytest.raises(OSError):
+ _yamlConfig(filepath="invalid path")
+
+ with patch("onaplogging.logWatchDog.config.dictConfig") as mock_config:
+ _yamlConfig(filepath=self.temp_file.name)
+ mock_config.assert_called_once_with(self.TEST_DICT)
+
+ with patch("onaplogging.logWatchDog.config.dictConfig") as mock_config:
+ with patch("onaplogging.logWatchDog.Observer.start") as mock_observer_start:
+ _yamlConfig(filepath=self.temp_file.name, watchDog=True)
+ mock_config.assert_called_once_with(self.TEST_DICT)
+ mock_observer_start.assert_called_once()
diff --git a/pylog/tests/test_marker.py b/pylog/tests/test_marker.py
new file mode 100644
index 0000000..c9e9f62
--- /dev/null
+++ b/pylog/tests/test_marker.py
@@ -0,0 +1,179 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+import sys
+import unittest
+from collections import namedtuple
+
+if sys.version_info[0] < 3:
+ from mock import patch
+if sys.version_info[0] >= 3:
+ from unittest.mock import patch
+
+import pytest
+
+from onaplogging.marker import BaseMarker, matchMarkerHelp, MarkerFactory, MarkerFilter, MarkerNotifyHandler
+
+
+class TestRecordMixin(object):
+
+ Record = namedtuple("Record", "marker")
+
+
+class TestNameMixin(object):
+
+ TEST_NAME = "test_base"
+
+
+class TestBaseMarker(unittest.TestCase, TestNameMixin):
+
+ def setUp(self):
+ super(TestBaseMarker, self).setUp()
+ self.base_marker = BaseMarker(name=self.TEST_NAME)
+
+ def test_base_marker_name(self):
+ with pytest.raises(TypeError):
+ BaseMarker(123)
+
+ with pytest.raises(ValueError):
+ BaseMarker(name="")
+
+ self.assertEqual(self.base_marker.getName(), self.TEST_NAME)
+
+ def test_base_marker_contains(self):
+ self.assertTrue(self.base_marker.contains(self.base_marker))
+ self.assertTrue(self.base_marker.contains(self.TEST_NAME))
+
+ def test_base_marker_compare(self):
+ self.assertNotEqual(self.base_marker, 3)
+ self.assertEqual(self.base_marker, self.base_marker)
+ other = BaseMarker("Other")
+ self.assertNotEqual(self.base_marker, other)
+ other = BaseMarker(self.TEST_NAME)
+ self.assertEqual(self.base_marker, other)
+
+ def test_base_marker_child(self):
+ self.assertListEqual(list(iter(self.base_marker)), [])
+ self.assertFalse(self.base_marker.contains(3))
+ with pytest.raises(TypeError):
+ self.base_marker.addChild(3)
+ with pytest.raises(TypeError):
+ self.base_marker.addChild("str")
+ with pytest.raises(TypeError):
+ self.base_marker.removeChild(3)
+
+ self.base_marker.addChild(self.base_marker)
+ self.assertListEqual(list(iter(self.base_marker)), [])
+
+ child1 = BaseMarker(name="child1")
+ self.assertFalse(self.base_marker.contains(child1))
+ self.base_marker.addChild(child1)
+ self.assertListEqual(list(iter(self.base_marker)), [child1])
+ self.assertTrue(self.base_marker.contains(child1))
+ self.base_marker.addChild(child1)
+ self.assertListEqual(list(iter(self.base_marker)), [child1])
+
+ self.base_marker.removeChild(child1)
+ self.assertListEqual(list(iter(self.base_marker)), [])
+ self.assertFalse(self.base_marker.contains(child1))
+
+ child2 = BaseMarker(name="child2")
+ self.assertFalse(self.base_marker.contains(child2))
+
+ with pytest.raises(TypeError):
+ self.base_marker.addChilds(None)
+ self.base_marker.addChilds((child1, child2,))
+ self.assertTrue(self.base_marker.contains(child1))
+ self.assertTrue(self.base_marker.contains(child2))
+ self.base_marker.removeChild(child1)
+ self.assertFalse(self.base_marker.contains(child1))
+ self.assertTrue(self.base_marker.contains(child2))
+ self.assertFalse(self.base_marker.contains("child1"))
+ self.assertTrue(self.base_marker.contains("child2"))
+
+
+class TestMatchMarkerHelp(unittest.TestCase, TestRecordMixin, TestNameMixin):
+ CHILD_NAME = "child"
+
+ def test_match_marker_help(self):
+ record = self.Record(None)
+ self.assertFalse(matchMarkerHelp(record, "anything"))
+
+ record = self.Record("not_marker_instance")
+ self.assertFalse(matchMarkerHelp(record, "not_marker_instance"))
+
+ marker = BaseMarker(self.TEST_NAME)
+ record = self.Record(marker)
+ self.assertFalse(matchMarkerHelp(record, "invalid_name"))
+ self.assertTrue(matchMarkerHelp(record, marker))
+ self.assertTrue(matchMarkerHelp(record, self.TEST_NAME))
+
+ child = BaseMarker(self.CHILD_NAME)
+ marker.addChild(child)
+ self.assertTrue(matchMarkerHelp(record, [self.TEST_NAME, self.CHILD_NAME]))
+ self.assertTrue(matchMarkerHelp(record, [marker, self.CHILD_NAME]))
+ self.assertTrue(matchMarkerHelp(record, [marker, child]))
+ self.assertTrue(matchMarkerHelp(record, [marker, "invalid"]))
+
+
+class TestMarkerFactory(unittest.TestCase, TestNameMixin):
+
+ def setUp(self):
+ super(TestMarkerFactory, self).setUp()
+ self.marker_factory = MarkerFactory()
+
+ def test_get_marker(self):
+ with pytest.raises(ValueError):
+ self.marker_factory.getMarker()
+ self.assertEqual(len(self.marker_factory._marker_map), 0)
+ marker = self.marker_factory.getMarker(self.TEST_NAME)
+ self.assertEqual(marker.getName(), self.TEST_NAME)
+ self.assertEqual(len(self.marker_factory._marker_map), 1)
+ marker = self.marker_factory.getMarker(self.TEST_NAME)
+ self.assertEqual(marker.getName(), self.TEST_NAME)
+ self.assertEqual(len(self.marker_factory._marker_map), 1)
+
+ self.assertTrue(self.marker_factory.exist(marker.getName()))
+
+ self.assertTrue(self.marker_factory.deleteMarker(marker.getName()))
+ self.assertFalse(self.marker_factory.exist(marker.getName()))
+ self.assertEqual(len(self.marker_factory._marker_map), 0)
+
+ self.assertFalse(self.marker_factory.deleteMarker(marker.getName()))
+
+
+class TestMarkerFilter(unittest.TestCase, TestRecordMixin, TestNameMixin):
+
+ def test_marker_filter(self):
+ marker_filter = MarkerFilter()
+
+ record = self.Record(BaseMarker(self.TEST_NAME))
+ self.assertFalse(marker_filter.filter(record))
+
+ marker_filter = MarkerFilter(markers=BaseMarker(self.TEST_NAME))
+ self.assertTrue(marker_filter.filter(record))
+
+
+class TestMarkerNotifyHandler(unittest.TestCase, TestRecordMixin, TestNameMixin):
+
+ def test_marker_notify_handler(self):
+ record = self.Record(BaseMarker(self.TEST_NAME))
+
+ notify_handler = MarkerNotifyHandler("test_host", "fromaddr", "toaddrs", "subject")
+ self.assertIsNone(notify_handler.markers)
+ self.assertFalse(notify_handler.handle(record))
+
+ marker = BaseMarker(self.TEST_NAME)
+ notify_handler = MarkerNotifyHandler("test_host", "fromaddr", "toaddrs", "subject", markers=[marker])
+ with patch("onaplogging.marker.markerHandler.SMTPHandler.handle") as mock_smtp_handler_handle:
+ mock_smtp_handler_handle.return_value = True
+ self.assertTrue(notify_handler.handle(record))
+ record = self.Record(BaseMarker("other"))
+ self.assertFalse(notify_handler.handle(record))
diff --git a/pylog/tests/test_marker_formatter.py b/pylog/tests/test_marker_formatter.py
new file mode 100644
index 0000000..c7ae6b1
--- /dev/null
+++ b/pylog/tests/test_marker_formatter.py
@@ -0,0 +1,67 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+import sys
+import unittest
+from collections import namedtuple
+
+if sys.version_info[0] < 3:
+ from mock import patch
+if sys.version_info[0] >= 3:
+ from unittest.mock import patch
+
+import pytest
+
+from onaplogging.marker import BaseMarker
+from onaplogging.markerFormatter import MarkerFormatter
+
+
+class TestMarkerFormatter(unittest.TestCase):
+
+ Record = namedtuple("Record", "marker")
+
+ def test_marker_formatter_init(self):
+ marker_formatter = MarkerFormatter()
+ self.assertEqual(marker_formatter.style, "%")
+ self.assertEqual(marker_formatter.marker_tag, "%(marker)s")
+
+ if sys.version_info[0] >= 3:
+ marker_formatter = MarkerFormatter(style="{")
+ self.assertEqual(marker_formatter.style, "{")
+ self.assertEqual(marker_formatter.marker_tag, "{marker}")
+
+ marker_formatter = MarkerFormatter(style="$")
+ self.assertEqual(marker_formatter.style, "$")
+ self.assertEqual(marker_formatter.marker_tag, "${marker}")
+
+ with pytest.raises(ValueError):
+ MarkerFormatter(style="*")
+
+ def test_marker_formatter_format(self):
+ record = self.Record(BaseMarker("test"))
+
+ with patch("onaplogging.markerFormatter.BaseColorFormatter.format") as mock_format:
+ marker_formatter = MarkerFormatter()
+ self.assertEqual(marker_formatter._fmt, "%(message)s")
+ self.assertEqual(marker_formatter.marker_tag, "%(marker)s")
+ marker_formatter.format(record)
+ mock_format.assert_called_once()
+ self.assertEqual(marker_formatter._fmt, "%(message)s")
+ self.assertEqual(marker_formatter.marker_tag, "%(marker)s")
+
+ with patch("onaplogging.markerFormatter.BaseColorFormatter.format") as mock_format:
+ marker_formatter = MarkerFormatter(fmt="%(message)s %(marker)s")
+ self.assertEqual(marker_formatter._fmt, "%(message)s %(marker)s")
+ self.assertEqual(marker_formatter.marker_tag, "%(marker)s")
+ marker_formatter.format(record)
+ mock_format.assert_called_once()
+ self.assertEqual(marker_formatter._fmt, "%(message)s %(marker)s")
+ self.assertEqual(marker_formatter.marker_tag, "%(marker)s")
+ self.assertEqual(marker_formatter.temp_fmt, "%(message)s %(marker)s")
diff --git a/pylog/tests/test_marker_log_adaptor.py b/pylog/tests/test_marker_log_adaptor.py
new file mode 100644
index 0000000..35f852f
--- /dev/null
+++ b/pylog/tests/test_marker_log_adaptor.py
@@ -0,0 +1,76 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+import sys
+import unittest
+
+if sys.version_info[0] < 3:
+ from mock import MagicMock, patch
+if sys.version_info[0] >= 3:
+ from unittest.mock import MagicMock, patch
+
+import pytest
+
+from onaplogging.marker import BaseMarker
+from onaplogging.markerLogAdaptor import MarkerLogAdaptor
+
+
+class TestMarkerLogAdaptor(unittest.TestCase):
+
+ def test_process(self):
+ log_adaptor = MarkerLogAdaptor(MagicMock(), extra=None)
+ msg, kwargs = log_adaptor.process("test", {})
+ self.assertEqual(msg, "test")
+ self.assertDictEqual(kwargs, {"extra": None})
+
+ log_adaptor = MarkerLogAdaptor(MagicMock(), extra={"A": "B"})
+ msg, kwargs = log_adaptor.process("test", {})
+ self.assertEqual(msg, "test")
+ self.assertDictEqual(kwargs, {"extra": {"A": "B"}})
+
+ # Commented out due to that: https://bugs.python.org/issue20239
+ # Comment out if Jenkis build runs using Python > 3.6
+ # def test_markers(self):
+ # log_adaptor = MarkerLogAdaptor(MagicMock(), extra=None)
+
+ # with patch("onaplogging.markerLogAdaptor.LoggerAdapter.info") as mock_info:
+ # log_adaptor.infoMarker(BaseMarker("info_marker"), "test_message")
+ # mock_info.assert_called_once()
+
+ # with patch("onaplogging.markerLogAdaptor.LoggerAdapter.debug") as mock_debug:
+ # log_adaptor.debugMarker(BaseMarker("info_marker"), "test_message")
+ # mock_debug.assert_called_once()
+
+ # with patch("onaplogging.markerLogAdaptor.LoggerAdapter.warning") as mock_warning:
+ # log_adaptor.warningMarker(BaseMarker("info_marker"), "test_message")
+ # mock_warning.assert_called_once()
+
+ # with patch("onaplogging.markerLogAdaptor.LoggerAdapter.error") as mock_error:
+ # log_adaptor.errorMarker(BaseMarker("info_marker"), "test_message")
+ # mock_error.assert_called_once()
+
+ # with patch("onaplogging.markerLogAdaptor.LoggerAdapter.exception") as mock_exception:
+ # log_adaptor.exceptionMarker(BaseMarker("info_marker"), "test_message")
+ # mock_exception.assert_called_once()
+
+ # with patch("onaplogging.markerLogAdaptor.LoggerAdapter.critical") as mock_critical:
+ # log_adaptor.criticalMarker(BaseMarker("info_marker"), "test_message")
+ # mock_critical.assert_called_once()
+
+ # with patch("onaplogging.markerLogAdaptor.LoggerAdapter.log") as mock_log:
+ # log_adaptor.logMarker(BaseMarker("info_marker"), "info", "test_message")
+ # mock_log.assert_called_once()
+
+ # with pytest.raises(TypeError):
+ # log_adaptor.infoMarker("info_marker_str", "test_message")
+
+ # with pytest.raises(Exception):
+ # log_adaptor = MarkerLogAdaptor(MagicMock(), extra={"marker": "exception"})
+ # log_adaptor.infoMarker(BaseMarker("info_marker"), "test_message")
diff --git a/pylog/tests/test_mdc_context.py b/pylog/tests/test_mdc_context.py
new file mode 100644
index 0000000..9e8b1bc
--- /dev/null
+++ b/pylog/tests/test_mdc_context.py
@@ -0,0 +1,189 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+import logging
+import sys
+import unittest
+
+if sys.version_info[0] < 3:
+ from mock import MagicMock, patch
+if sys.version_info[0] >= 3:
+ from unittest.mock import MagicMock, patch
+
+import pytest
+
+from onaplogging.mdcContext import (
+ _getmdcs,
+ MDCContext,
+ info,
+ debug,
+ warning,
+ exception,
+ critical,
+ error,
+ log,
+ handle
+)
+
+
+class TestMDCContext(unittest.TestCase):
+
+ def setUp(self):
+ super(TestMDCContext, self).setUp()
+
+ self.TEST_KEY = "key"
+ self.TEST_VALUE = "value"
+
+ self.mdc_context = MDCContext()
+
+ def test_mdc_context(self):
+
+ self.assertTrue(self.mdc_context.isEmpty())
+ self.assertIsNone(self.mdc_context.get(self.TEST_KEY))
+ self.mdc_context.remove(self.TEST_KEY)
+ self.mdc_context.put(self.TEST_KEY, self.TEST_VALUE)
+ self.assertFalse(self.mdc_context.isEmpty())
+ self.assertEqual(self.mdc_context.get(self.TEST_KEY), self.TEST_VALUE)
+ self.assertDictEqual(self.mdc_context.result(), {self.TEST_KEY: self.TEST_VALUE})
+ self.mdc_context.remove(self.TEST_KEY)
+ self.assertTrue(self.mdc_context.isEmpty())
+ self.assertDictEqual(self.mdc_context.result(), {})
+ self.mdc_context.put(self.TEST_KEY, self.TEST_VALUE)
+ self.assertFalse(self.mdc_context.isEmpty())
+ self.assertEqual(self.mdc_context.get(self.TEST_KEY), self.TEST_VALUE)
+ self.assertDictEqual(self.mdc_context.result(), {self.TEST_KEY: self.TEST_VALUE})
+ self.mdc_context.clear()
+ self.assertTrue(self.mdc_context.isEmpty())
+ self.assertDictEqual(self.mdc_context.result(), {})
+
+ def test_getmdcs(self):
+ with patch("onaplogging.mdcContext.MDC", self.mdc_context):
+ self.assertIsNone(_getmdcs(None))
+ self.mdc_context.put(self.TEST_KEY, self.TEST_VALUE)
+ self.assertDictEqual(_getmdcs(None), {"mdc": {self.TEST_KEY: self.TEST_VALUE}})
+ self.assertDictEqual(_getmdcs({"test": "value"}), {"mdc": {self.TEST_KEY: self.TEST_VALUE}, "test": "value"})
+ with pytest.raises(KeyError):
+ _getmdcs({self.TEST_KEY: self.TEST_VALUE})
+ with pytest.raises(KeyError):
+ _getmdcs({"mdc": "exception"})
+
+ def test_fetchkeys_info(self):
+ with patch("onaplogging.mdcContext.MDC", self.mdc_context):
+ test_self = MagicMock()
+ test_self.isEnabledFor.return_value = False
+ info(test_self, "msg")
+ test_self._log.assert_not_called()
+ test_self.isEnabledFor.return_value = True
+ info(test_self, "msg")
+ test_self._log.assert_called_once_with(logging.INFO, "msg", (), extra=None)
+ test_self._log.reset_mock()
+ self.mdc_context.put(self.TEST_KEY, self.TEST_VALUE)
+ info(test_self, "msg")
+ test_self._log.assert_called_once_with(logging.INFO, "msg", (), extra={"mdc": {self.TEST_KEY: self.TEST_VALUE}})
+
+ def test_fetchkeys_debug(self):
+ with patch("onaplogging.mdcContext.MDC", self.mdc_context):
+ test_self = MagicMock()
+ test_self.isEnabledFor.return_value = False
+ debug(test_self, "msg")
+ test_self._log.assert_not_called()
+ test_self.isEnabledFor.return_value = True
+ debug(test_self, "msg")
+ test_self._log.assert_called_once_with(logging.DEBUG, "msg", (), extra=None)
+ test_self._log.reset_mock()
+ self.mdc_context.put(self.TEST_KEY, self.TEST_VALUE)
+ debug(test_self, "msg")
+ test_self._log.assert_called_once_with(logging.DEBUG, "msg", (), extra={"mdc": {self.TEST_KEY: self.TEST_VALUE}})
+
+ def test_fetchkeys_warning(self):
+ with patch("onaplogging.mdcContext.MDC", self.mdc_context):
+ test_self = MagicMock()
+ test_self.isEnabledFor.return_value = False
+ warning(test_self, "msg")
+ test_self._log.assert_not_called()
+ test_self.isEnabledFor.return_value = True
+ warning(test_self, "msg")
+ test_self._log.assert_called_once_with(logging.WARNING, "msg", (), extra=None)
+ test_self._log.reset_mock()
+ self.mdc_context.put(self.TEST_KEY, self.TEST_VALUE)
+ warning(test_self, "msg")
+ test_self._log.assert_called_once_with(logging.WARNING, "msg", (), extra={"mdc": {self.TEST_KEY: self.TEST_VALUE}})
+
+ def test_fetchkeys_exception(self):
+ with patch("onaplogging.mdcContext.MDC", self.mdc_context):
+ test_self = MagicMock()
+ test_self.isEnabledFor.return_value = False
+ exception(test_self, "msg")
+ test_self.error.assert_called_once_with("msg", exc_info=1, extra=None)
+
+ def test_fetchkeys_critical(self):
+ with patch("onaplogging.mdcContext.MDC", self.mdc_context):
+ test_self = MagicMock()
+ test_self.isEnabledFor.return_value = False
+ critical(test_self, "msg")
+ test_self._log.assert_not_called()
+ test_self.isEnabledFor.return_value = True
+ critical(test_self, "msg")
+ test_self._log.assert_called_once_with(logging.CRITICAL, "msg", (), extra=None)
+ test_self._log.reset_mock()
+ self.mdc_context.put(self.TEST_KEY, self.TEST_VALUE)
+ critical(test_self, "msg")
+ test_self._log.assert_called_once_with(logging.CRITICAL, "msg", (), extra={"mdc": {self.TEST_KEY: self.TEST_VALUE}})
+
+ def test_fetchkeys_error(self):
+ with patch("onaplogging.mdcContext.MDC", self.mdc_context):
+ test_self = MagicMock()
+ test_self.isEnabledFor.return_value = False
+ error(test_self, "msg")
+ test_self._log.assert_not_called()
+ test_self.isEnabledFor.return_value = True
+ error(test_self, "msg")
+ test_self._log.assert_called_once_with(logging.ERROR, "msg", (), extra=None)
+ test_self._log.reset_mock()
+ self.mdc_context.put(self.TEST_KEY, self.TEST_VALUE)
+ error(test_self, "msg")
+ test_self._log.assert_called_once_with(logging.ERROR, "msg", (), extra={"mdc": {self.TEST_KEY: self.TEST_VALUE}})
+
+ def test_fetchkeys_log(self):
+ with patch("onaplogging.mdcContext.MDC", self.mdc_context):
+ test_self = MagicMock()
+ test_self.isEnabledFor.return_value = False
+ logging.raiseExceptions = False
+ log(test_self, "invalid_level", "msg")
+ logging.raiseExceptions = True
+ with pytest.raises(TypeError):
+ log(test_self, "invalid_level", "msg")
+ log(test_self, logging.DEBUG, "msg")
+ test_self._log.assert_not_called()
+ test_self.isEnabledFor.return_value = True
+ log(test_self, logging.DEBUG, "msg")
+ test_self._log.assert_called_once()
+
+ def test_handle(self):
+ with patch("onaplogging.mdcContext.MDC", self.mdc_context):
+ test_self = MagicMock()
+ record = MagicMock()
+ test_self.disabled = True
+ test_self.filter.return_value = False
+ handle(test_self, record)
+ test_self.callHandlers.assert_not_called()
+
+ test_self.disabled = False
+ test_self.filter.return_value = False
+ handle(test_self, record)
+ test_self.callHandlers.assert_not_called()
+ test_self.filter.assert_called_once_with(record)
+
+ test_self.filter.reset_mock()
+ test_self.disabled = False
+ test_self.filter.return_value = True
+ handle(test_self, record)
+ test_self.callHandlers.assert_called_once()
+ test_self.filter.assert_called_once_with(record)
diff --git a/pylog/tests/test_mdc_formatter.py b/pylog/tests/test_mdc_formatter.py
new file mode 100644
index 0000000..6866b9d
--- /dev/null
+++ b/pylog/tests/test_mdc_formatter.py
@@ -0,0 +1,108 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+import sys
+import unittest
+
+if sys.version_info[0] < 3:
+ from mock import MagicMock, patch
+if sys.version_info[0] >= 3:
+ from unittest.mock import MagicMock, patch
+
+import pytest
+
+from onaplogging.mdcformatter import MDCFormatter
+
+
+class TestMdcFormatter(unittest.TestCase):
+
+ def test_mdc_formatter_init(self):
+ mdc_formatter = MDCFormatter()
+ self.assertEqual(mdc_formatter.style, "%")
+ self.assertEqual(mdc_formatter._mdc_tag, "%(mdc)s")
+ self.assertEqual(mdc_formatter._mdcFmt, "{reqeustID}")
+
+ mdc_formatter = MDCFormatter(mdcfmt="{test}")
+ self.assertEqual(mdc_formatter.style, "%")
+ self.assertEqual(mdc_formatter._mdc_tag, "%(mdc)s")
+ self.assertEqual(mdc_formatter._mdcFmt, "{test}")
+
+ if sys.version_info[0] >= 3:
+ mdc_formatter = MDCFormatter(style="{")
+ self.assertEqual(mdc_formatter.style, "{")
+ self.assertEqual(mdc_formatter._mdc_tag, "{mdc}")
+ self.assertEqual(mdc_formatter._mdcFmt, "{reqeustID}")
+
+ mdc_formatter = MDCFormatter(style="$")
+ self.assertEqual(mdc_formatter.style, "$")
+ self.assertEqual(mdc_formatter._mdc_tag, "${mdc}")
+ self.assertEqual(mdc_formatter._mdcFmt, "{reqeustID}")
+
+ with pytest.raises(ValueError):
+ MDCFormatter(style="*")
+
+ def test_mdc_fmt_key(self):
+ mdc_formatter = MDCFormatter()
+ brace, not_brace = mdc_formatter._mdcfmtKey()
+ self.assertEqual(brace, ["{reqeustID}"])
+ self.assertEqual(list(not_brace), ["reqeustID"])
+
+ mdc_formatter = MDCFormatter(mdcfmt="{test} {value} {anything}")
+ brace, not_brace = mdc_formatter._mdcfmtKey()
+ self.assertEqual(brace, ["{test}", "{value}", "{anything}"])
+ self.assertEqual(list(not_brace), ["test", "value", "anything"])
+
+ mdc_formatter = MDCFormatter(mdcfmt="no_braces")
+ brace, not_brace = mdc_formatter._mdcfmtKey()
+ self.assertEqual(brace, [])
+ self.assertIsNone(not_brace)
+
+ mdc_formatter = MDCFormatter(mdcfmt="}what?{")
+ brace, not_brace = mdc_formatter._mdcfmtKey()
+ self.assertEqual(brace, [])
+ self.assertIsNone(not_brace)
+
+ mdc_formatter = MDCFormatter(mdcfmt="}{hello}{")
+ brace, not_brace = mdc_formatter._mdcfmtKey()
+ self.assertEqual(brace, ["{hello}"])
+ self.assertEqual(list(not_brace), ["hello"])
+
+ mdc_formatter = MDCFormatter(mdcfmt="}{}{hel{lo}{")
+ brace, not_brace = mdc_formatter._mdcfmtKey()
+ self.assertEqual(brace, [])
+ self.assertIsNone(not_brace)
+
+ def test_format(self):
+ record = MagicMock()
+ with patch("onaplogging.mdcformatter.MarkerFormatter.format") as mock_marker_formatter_format:
+ mdc_formatter = MDCFormatter()
+ mdc_formatter.format(record)
+ mock_marker_formatter_format.assert_called_once_with(record)
+ self.assertEqual(mdc_formatter._fmt, "%(message)s")
+
+ if sys.version_info[0] >= 3:
+ with patch("onaplogging.mdcformatter.MarkerFormatter.format") as mock_marker_formatter_format:
+ mdc_formatter = MDCFormatter(fmt="{mdc}", style="{", mdcfmt="{key}")
+ mdc_formatter.format(record)
+ mock_marker_formatter_format.assert_called_once_with(record)
+ self.assertEqual(mdc_formatter._fmt, "key=")
+
+ record.mdc = {"key": 123}
+ with patch("onaplogging.mdcformatter.MarkerFormatter.format") as mock_marker_formatter_format:
+ mdc_formatter = MDCFormatter(fmt="{mdc}", style="{", mdcfmt="no_braces")
+ mdc_formatter.format(record)
+ mock_marker_formatter_format.assert_called_once_with(record)
+ self.assertEqual(mdc_formatter._fmt, "")
+
+ with patch("onaplogging.mdcformatter.MarkerFormatter.format") as mock_marker_formatter_format:
+ mdc_formatter = MDCFormatter(fmt="{mdc}", style="{", mdcfmt="{key}")
+ mdc_formatter.format(record)
+ mock_marker_formatter_format.assert_called_once_with(record)
+ self.assertEqual(mdc_formatter._fmt, "key=123")
diff --git a/pylog/tests/test_monkey.py b/pylog/tests/test_monkey.py
new file mode 100644
index 0000000..9b64b62
--- /dev/null
+++ b/pylog/tests/test_monkey.py
@@ -0,0 +1,47 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+import sys
+import unittest
+
+if sys.version_info[0] < 3:
+ from mock import patch
+if sys.version_info[0] >= 3:
+ from unittest.mock import patch
+
+from onaplogging.monkey import patch_all, patch_logging_yaml, patch_logging_mdc
+
+
+class TestMonkey(unittest.TestCase):
+
+ def test_patch_all(self):
+ with patch("onaplogging.monkey.patch_logging_mdc") as mock_mdc:
+ with patch("onaplogging.monkey.patch_logging_yaml") as mock_yaml:
+ patch_all()
+ mock_mdc.assert_called_once()
+ mock_yaml.assert_called_once()
+
+ with patch("onaplogging.monkey.patch_logging_mdc") as mock_mdc:
+ with patch("onaplogging.monkey.patch_logging_yaml") as mock_yaml:
+ patch_all(mdc=False)
+ mock_mdc.assert_not_called()
+ mock_yaml.assert_called_once()
+
+ with patch("onaplogging.monkey.patch_logging_mdc") as mock_mdc:
+ with patch("onaplogging.monkey.patch_logging_yaml") as mock_yaml:
+ patch_all(yaml=False)
+ mock_mdc.assert_called_once()
+ mock_yaml.assert_not_called()
+
+ with patch("onaplogging.monkey.patch_logging_mdc") as mock_mdc:
+ with patch("onaplogging.monkey.patch_logging_yaml") as mock_yaml:
+ patch_all(mdc=False, yaml=False)
+ mock_mdc.assert_not_called()
+ mock_yaml.assert_not_called()
diff --git a/pylog/tests/test_utils.py b/pylog/tests/test_utils.py
new file mode 100644
index 0000000..a118361
--- /dev/null
+++ b/pylog/tests/test_utils.py
@@ -0,0 +1,45 @@
+# Copyright (c) 2020 Deutsche Telekom.
+# 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.
+
+import sys
+
+import unittest
+if sys.version_info[0] < 3:
+ from mock import patch, MagicMock
+if sys.version_info[0] >= 3:
+ from unittest.mock import patch, MagicMock
+
+from onaplogging.utils.system import is_above_python_2_7, is_above_python_3_2
+
+
+class TestUtils(unittest.TestCase):
+
+ def test_is_above_python_3_2(self):
+ with patch("onaplogging.utils.system.sys.version_info", (3, 4, 7)):
+ assert is_above_python_3_2() is True
+
+ with patch("onaplogging.utils.system.sys.version_info", (2, 7, 5)):
+ assert is_above_python_3_2() is False
+
+ with patch("onaplogging.utils.system.sys.version_info", (3, 2, 0, "final", 0)):
+ assert is_above_python_3_2() is True
+
+ def test_is_above_python_2_7(self):
+ with patch("onaplogging.utils.system.sys.version_info", (3, 4, 7)):
+ assert is_above_python_2_7() is True
+
+ with patch("onaplogging.utils.system.sys.version_info", (2, 7, 5)):
+ assert is_above_python_2_7() is True
+
+ with patch("onaplogging.utils.system.sys.version_info", (2, 5, 6)):
+ assert is_above_python_2_7() is False
+
+ with patch("onaplogging.utils.system.sys.version_info", (2, 7, 0, "final", 0)):
+ assert is_above_python_2_7() is True
diff --git a/pylog/tox.ini b/pylog/tox.ini
index bf6b784..355385c 100644
--- a/pylog/tox.ini
+++ b/pylog/tox.ini
@@ -1,5 +1,11 @@
[tox]
-envlist =py,py3,pep8
+envlist =
+ py27
+ py36
+ py37
+ py38
+ pep8
+ cover
skipsdist = true
skip_missing_interpreters = true
@@ -7,23 +13,20 @@ skip_missing_interpreters = true
downloadcache = ~/cache/pip
[testenv]
-deps = -r{toxinidir}/requirements.txt
- pytest
+deps = -r{toxinidir}/test_requirements.txt
coverage
pytest-cov
setenv = PYTHONPATH={toxinidir}/
+commands = pytest
-commands =
- /usr/bin/find . -type f -name "*.py[c|o]" -delete
- py.test
+[flake8]
+ignore = E271, E125, E128, E127
[testenv:pep8]
+basepython = python3
deps=flake8
-commands=flake8
-
-[flake8]
-show-source = true
-exclude = env,venv,.venv,.git,.tox,dist,doc,*egg,build
+commands=flake8 onaplogging
[testenv:cover]
-commands = py.test --cov onaplogging
+basepython = python3
+commands = py.test --cov-report term-missing --cov onaplogging
diff --git a/pylog/version.properties b/pylog/version.properties
index 176b32a..ada21df 100644
--- a/pylog/version.properties
+++ b/pylog/version.properties
@@ -18,8 +18,8 @@
# because they are used in Jenkins, whose plug-in doesn't support
# 1.2.6-SNAPSHOT is off 1.2.2
major=1
-minor=4
-patch=0
+minor=6
+patch=10
base_version=${major}.${minor}.${patch}
diff --git a/reference/.classpath b/reference/.classpath
deleted file mode 100644
index 1767a9d..0000000
--- a/reference/.classpath
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
- <attributes>
- <attribute name="module" value="true"/>
- <attribute name="owner.project.facets" value="java"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="output" path="target"/>
-</classpath>
diff --git a/reference/.gitignore b/reference/.gitignore
deleted file mode 100644
index 99d2bb1..0000000
--- a/reference/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/target/
-/build/
diff --git a/reference/.project b/reference/.project
deleted file mode 100644
index 15686ec..0000000
--- a/reference/.project
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>logging-reference</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.common.project.facet.core.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.springframework.ide.eclipse.core.springnature</nature>
- <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
- <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
- <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
- </natures>
-</projectDescription>
diff --git a/reference/logging-demo/.classpath b/reference/logging-demo/.classpath
deleted file mode 100644
index 407b61f..0000000
--- a/reference/logging-demo/.classpath
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
diff --git a/reference/logging-demo/.gitignore b/reference/logging-demo/.gitignore
deleted file mode 100644
index eeca7fe..0000000
--- a/reference/logging-demo/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/target/
-/build/
-/bin/
diff --git a/reference/logging-demo/.project b/reference/logging-demo/.project
deleted file mode 100644
index ee4ad0b..0000000
--- a/reference/logging-demo/.project
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>logging-demo</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.common.project.facet.core.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.springframework.ide.eclipse.core.springnature</nature>
- <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
- <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
- <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
- </natures>
-</projectDescription>
diff --git a/reference/logging-demo/pom.xml b/reference/logging-demo/pom.xml
index 1988407..cb0baf7 100644
--- a/reference/logging-demo/pom.xml
+++ b/reference/logging-demo/pom.xml
@@ -1,112 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
<parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-reference</artifactId>
- <version>1.6.2-SNAPSHOT</version>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-reference</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
</parent>
+
<artifactId>logging-demo</artifactId>
<packaging>war</packaging>
- <name>logging-demo</name>
+
+ <name>logging-analytics :: ${project.artifactId}</name>
+
<properties>
- <jackson-2-version>2.8.6</jackson-2-version>
- <!-- https://mvnrepository.com/artifact/org.springframework/spring-aop/5.0.5.RELEASE -->
- <spring.version>5.1.2.RELEASE</spring.version>
- <logback.version>1.2.3</logback.version>
+ <jackson-2-version>2.8.6</jackson-2-version>
+ <!-- https://mvnrepository.com/artifact/org.springframework/spring-aop/5.0.5.RELEASE -->
+ <spring.version>5.1.2.RELEASE</spring.version>
+ <logback.version>1.2.3</logback.version>
</properties>
- <build>
- <plugins>
- <!-- Checkstyle plugin - used to report on compliance with -->
- <!-- the Google style guide. -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-site-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.2</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- </plugins>
- <pluginManagement>
- <plugins>
- <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
- <plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>
- org.apache.maven.plugins
- </groupId>
- <artifactId>
- maven-compiler-plugin
- </artifactId>
- <versionRange>
- [3.2,)
- </versionRange>
- <goals>
- <goal>testCompile</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore></ignore>
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
- <dependencies>
- <dependency>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-mock-service</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <!-- https://jersey.java.net/documentation/latest/modules-and-dependencies.html -->
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-mock-service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- https://jersey.java.net/documentation/latest/modules-and-dependencies.html -->
<dependency>
- <groupId>javax.ws.rs</groupId>
- <artifactId>javax.ws.rs-api</artifactId>
- <version>2.0.1</version>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <version>2.0.1</version>
</dependency>
<dependency>
- <groupId>org.glassfish.jersey.containers</groupId>
- <artifactId>jersey-container-servlet</artifactId>
- <version>2.23</version>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ <version>2.23</version>
</dependency>
<dependency>
- <groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-server</artifactId>
- <version>2.23</version>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <version>2.23</version>
</dependency>
<dependency>
- <groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-client</artifactId>
- <version>2.23</version>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>2.23</version>
</dependency>
<dependency>
- <groupId>org.glassfish.jersey.media</groupId>
- <artifactId>jersey-media-multipart</artifactId>
- <version>2.23</version>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ <version>2.23</version>
</dependency>
<!-- fixes http://stackoverflow.com/questions/23442440/messagebodyreader-not-found-for-media-type-application-json -->
<dependency>
- <groupId>org.glassfish.jersey.media</groupId>
- <artifactId>jersey-media-json-jackson</artifactId>
- <version>2.23</version>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ <version>2.23</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
@@ -116,182 +66,175 @@
</dependency>
<!-- for spring injection in rest -->
<dependency>
- <groupId>org.glassfish.jersey.ext</groupId>
- <artifactId>jersey-spring3</artifactId>
- <version>2.23</version>
- <!-- for https://github.com/JakubStas/SpringWithSwagger/issues/2 -->
- <exclusions>
- <exclusion>
- <artifactId>spring-context</artifactId>
- <groupId>org.springframework</groupId>
- </exclusion>
- <exclusion>
- <artifactId>spring-core</artifactId>
- <groupId>org.springframework</groupId>
- </exclusion>
- <exclusion>
- <artifactId>spring-web</artifactId>
- <groupId>org.springframework</groupId>
- </exclusion>
- <exclusion>
- <artifactId>spring-beans</artifactId>
- <groupId>org.springframework</groupId>
- </exclusion>
- <exclusion>
- <groupId>org.glassfish.hk2.external</groupId>
- <artifactId>bean-validator</artifactId>
- </exclusion>
- </exclusions>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-spring3</artifactId>
+ <version>2.23</version>
+ <!-- for https://github.com/JakubStas/SpringWithSwagger/issues/2 -->
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ </exclusion>
+ <exclusion>
+ <artifactId>spring-core</artifactId>
+ <groupId>org.springframework</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>spring-web</artifactId>
+ <groupId>org.springframework</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>spring-beans</artifactId>
+ <groupId>org.springframework</groupId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.glassfish.hk2.external</groupId>
+ <artifactId>bean-validator</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
- <!-- json parsing -->
-<!-- the core, which includes Streaming API, shared low-level abstractions (but NOT data-binding) -->
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- <version>${jackson-2-version}</version>
- </dependency>
-
- <!-- Just the annotations; use this dependency if you want to attach annotations
- to classes without connecting them to the code. -->
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- <version>${jackson-2-version}</version>
-</dependency>
-
-<!-- databinding; ObjectMapper, JsonNode and related classes are here -->
-<!--<dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>${jackson-2-version}</version>
-</dependency>-->
-
-<!-- smile (binary JSON). Other artifacts in this group do other formats. -->
-<dependency>
- <groupId>com.fasterxml.jackson.dataformat</groupId>
- <artifactId>jackson-dataformat-smile</artifactId>
- <version>${jackson-2-version}</version>
-</dependency>
-<!-- JAX-RS provider -->
-<dependency>
- <groupId>com.fasterxml.jackson.jaxrs</groupId>
- <artifactId>jackson-jaxrs-json-provider</artifactId>
- <version>${jackson-2-version}</version>
- <exclusions>
- <exclusion>
+ <!-- json parsing -->
+ <!-- the core, which includes Streaming API, shared low-level abstractions (but NOT data-binding) -->
+ <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- </exclusion>
- </exclusions>
-</dependency>
-<!-- Support for JAX-B annotations as additional configuration -->
-<dependency>
- <groupId>com.fasterxml.jackson.module</groupId>
- <artifactId>jackson-module-jaxb-annotations</artifactId>
- <version>${jackson-2-version}</version>
- <exclusions>
- <exclusion>
+ <artifactId>jackson-core</artifactId>
+ <version>${jackson-2-version}</version>
+ </dependency>
+ <!-- Just the annotations; use this dependency if you want to attach annotations to classes without connecting them to the code. -->
+ <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- </exclusion>
- </exclusions>
-</dependency>
+ <artifactId>jackson-annotations</artifactId>
+ <version>${jackson-2-version}</version>
+ </dependency>
+ <!-- databinding; ObjectMapper, JsonNode and related classes are here -->
+ <!--<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson-2-version}</version> </dependency> -->
+ <!-- smile (binary JSON). Other artifacts in this group do other formats. -->
<dependency>
- <groupId>com.owlike</groupId>
- <artifactId>genson</artifactId>
- <version>1.1</version>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-smile</artifactId>
+ <version>${jackson-2-version}</version>
+ </dependency>
+ <!-- JAX-RS provider -->
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-json-provider</artifactId>
+ <version>${jackson-2-version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <!-- Support for JAX-B annotations as additional configuration -->
+ <dependency>
+ <groupId>com.fasterxml.jackson.module</groupId>
+ <artifactId>jackson-module-jaxb-annotations</artifactId>
+ <version>${jackson-2-version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.owlike</groupId>
+ <artifactId>genson</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.0.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-orm</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-oxm</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ <!--scope>test</scope -->
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aspects</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>1.9.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${spring.version}</version>
</dependency>
- <!-- dependency>
- <groupId>org.eclipse.persistence</groupId>
- <artifactId>javax.persistence</artifactId>
- <version>2.0.0</version>
- </dependency-->
-
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.0.1</version>
- <scope>provided</scope>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>${logback.version}</version>
</dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
+ <!-- JUnit 4.12 used to come with EELF -->
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.6.4</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aop</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-orm</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-oxm</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>${spring.version}</version>
- <!--scope>test</scope-->
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aspects</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjrt</artifactId>
- <version>1.9.1</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-tx</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-webmvc</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- <version>${logback.version}</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>${logback.version}</version>
- </dependency>
- <!-- JUnit 4.12 used to come with EELF -->
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <version>1.6.4</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.12</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/reference/logging-docker-root/.project b/reference/logging-docker-root/.project
deleted file mode 100644
index f1679d2..0000000
--- a/reference/logging-docker-root/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>logging-docker-root</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- </natures>
-</projectDescription>
diff --git a/reference/logging-docker-root/pom.xml b/reference/logging-docker-root/pom.xml
index e52e2bb..9c75069 100644
--- a/reference/logging-docker-root/pom.xml
+++ b/reference/logging-docker-root/pom.xml
@@ -1,12 +1,15 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
<parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-reference</artifactId>
- <version>1.6.2-SNAPSHOT</version>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-reference</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
</parent>
+
<artifactId>logging-docker-root</artifactId>
<packaging>pom</packaging>
- <name>logging-docker-root</name>
+
+ <name>logging-analytics :: ${project.artifactId}</name>
</project>
diff --git a/reference/logging-filter/logging-filter-base/pom.xml b/reference/logging-filter/logging-filter-base/pom.xml
index cab541c..09a5048 100644
--- a/reference/logging-filter/logging-filter-base/pom.xml
+++ b/reference/logging-filter/logging-filter-base/pom.xml
@@ -1,62 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-filter-parent</artifactId>
- <version>1.6.2-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-filter-parent</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
+ </parent>
- <artifactId>logging-filter-base</artifactId>
+ <artifactId>logging-filter-base</artifactId>
- <dependencies>
- <dependency>
- <groupId>javax.annotation</groupId>
- <artifactId>javax.annotation-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-slf4j</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.ws.rs</groupId>
- <artifactId>javax.ws.rs-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-client</artifactId>
- <version>2.25.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <version>2.10.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <name>logging-analytics :: ${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-slf4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>2.25.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <version>2.10.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java
index ce2f448..d8394a7 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java
@@ -44,7 +44,7 @@ public abstract class AbstractAuditLogFilter<GenericRequest, GenericResponse> ex
additionalPreHandling(request);
setLogTimestamp();
setElapsedTime();
- logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
+ logEntering();
} catch (Exception e) {
logger.warn("Error in AbstractInboundFilter pre", e);
}
@@ -52,14 +52,15 @@ public abstract class AbstractAuditLogFilter<GenericRequest, GenericResponse> ex
protected void post(GenericResponse response) {
try {
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, MDC.get(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID));
int responseCode = getResponseCode(response);
setResponseStatusCode(responseCode);
MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, String.valueOf(responseCode));
setResponseDescription(responseCode);
setLogTimestamp();
setElapsedTime();
- logger.info(ONAPLogConstants.Markers.EXIT, "Exiting.");
additionalPostHandling(response);
+ logExiting();
} catch (Exception e) {
logger.warn("Error in AbstractInboundFilter post", e);
} finally {
@@ -79,4 +80,12 @@ public abstract class AbstractAuditLogFilter<GenericRequest, GenericResponse> ex
// override to add additional post handling
}
+ protected void logEntering() {
+ logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
+ }
+
+ protected void logExiting() {
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting.");
+ }
+
}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractBaseMetricLogFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractBaseMetricLogFilter.java
new file mode 100644
index 0000000..4dd1b49
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractBaseMetricLogFilter.java
@@ -0,0 +1,134 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.UUID;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
+public abstract class AbstractBaseMetricLogFilter<Request, Response> extends MDCSetup {
+ protected static final Logger logger = LoggerFactory.getLogger(AbstractBaseMetricLogFilter.class);
+ protected final String partnerName;
+ protected static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN");
+
+ public AbstractBaseMetricLogFilter() {
+ partnerName = getPartnerName();
+ }
+
+ protected abstract String getTargetServiceName(Request request);
+
+ protected abstract int getHttpStatusCode(Response response);
+
+ protected abstract String getResponseCode(Response response);
+
+ protected abstract String getTargetEntity(Request request);
+
+ protected void pre(Request request) {
+ try {
+ setupMDC(request);
+ extractRequestID();
+ setInvocationId();
+ additionalPre(request);
+ logRequest();
+ } catch (Exception e) {
+ logger.warn("Error in AbstractBaseMetricLogFilter pre", e);
+ }
+ }
+
+ protected void additionalPre(Request request) {
+ // override to add application specific logic
+ }
+
+ protected String setInvocationId() {
+ String invocationId = UUID.randomUUID().toString();
+ MDC.put(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID, invocationId);
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
+ return invocationId;
+ }
+
+ protected void setupMDC(Request request) {
+ MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, getCurrentTimeStamp());
+ MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, getTargetServiceName(request));
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
+
+ if (MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY) == null) {
+ String targetEntity = getTargetEntity(request);
+ if (targetEntity != null) {
+ MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, targetEntity);
+ } else {
+ MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, Constants.DefaultValues.UNKNOWN_TARGET_ENTITY);
+ }
+ }
+ setServerFQDN();
+ setLogTimestamp();
+ setElapsedTimeInvokeTimestamp();
+ }
+
+ protected String extractRequestID() {
+ String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
+ if (requestId == null || requestId.isEmpty()) {
+ requestId = UUID.randomUUID().toString();
+ logger.trace("No value found in MDC when checking key {} value will be set to {}",
+ ONAPLogConstants.MDCs.REQUEST_ID, requestId);
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
+ }
+ return requestId;
+ }
+
+ protected void post(Request request, Response response) {
+ try {
+ setLogTimestamp();
+ setElapsedTimeInvokeTimestamp();
+ setResponseStatusCode(getHttpStatusCode(response));
+ setResponseDescription(getHttpStatusCode(response));
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, getResponseCode(response));
+ additionalPost(request, response);
+ logResponse();
+ clearClientMDCs();
+ } catch (Exception e) {
+ logger.warn("Error in AbstractBaseMetricLogFilter post", e);
+ }
+ }
+
+ protected void additionalPost(Request request, Response response) {
+ // override to add application specific logic
+ }
+
+ protected String getPartnerName() {
+ return getProperty(Constants.Property.PARTNER_NAME);
+ }
+
+ protected void logRequest() {
+ logger.info(ONAPLogConstants.Markers.INVOKE, "Invoke");
+ }
+
+ protected void logResponse() {
+ logger.info(INVOKE_RETURN, "InvokeReturn");
+ }
+
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMDCSetupAspect.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMDCSetupAspect.java
new file mode 100644
index 0000000..c9424c4
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMDCSetupAspect.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+import java.util.UUID;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.MDC;
+
+public abstract class AbstractMDCSetupAspect extends MDCSetup {
+
+ public abstract void logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable;
+
+ protected void setupMDC(String methodName) {
+ try {
+ setEntryTimeStamp();
+ setServerFQDN();
+ String partnerName = getProperty(Constants.Property.PARTNER_NAME);
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, UUID.randomUUID().toString());
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, UUID.randomUUID().toString());
+ MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, partnerName);
+ MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, Constants.DefaultValues.UNKNOWN);
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, methodName);
+ setLogTimestamp();
+ setElapsedTime();
+ MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName);
+ logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
+ } catch (Exception e) {
+ logger.warn("Error in ScheduledTasksMDCSetup: {}", e.getMessage());
+ }
+ }
+
+ protected void exitAndClearMDC() {
+ try {
+ setStatusCode();
+ setLogTimestamp();
+ setElapsedTime();
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting.");
+ } catch (Exception e) {
+ logger.warn("Error in ScheduledTasksMDCSetup clear MDC: {}", e.getMessage());
+ }
+ MDC.clear();
+ }
+
+ protected void setStatusCode() {
+ String currentStatusCode = MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE);
+ if (currentStatusCode == null || !currentStatusCode.equals(ONAPLogConstants.ResponseStatus.ERROR.toString())) {
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.COMPLETE.toString());
+ }
+ }
+
+ public void errorMDCSetup(ErrorCode errorCode, String errorDescription) {
+ MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, String.valueOf(errorCode.getValue()));
+ MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, errorDescription);
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.ERROR.toString());
+ }
+
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java
index 4e164ae..bdba9b6 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java
@@ -20,42 +20,27 @@
package org.onap.logging.filter.base;
-import java.time.ZoneOffset;
-import java.time.ZonedDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.UUID;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
-import org.slf4j.Marker;
-import org.slf4j.MarkerFactory;
-public abstract class AbstractMetricLogFilter<Request, Response, RequestHeaders> extends MDCSetup {
+public abstract class AbstractMetricLogFilter<Request, Response, RequestHeaders>
+ extends AbstractBaseMetricLogFilter<Request, Response> {
protected static final Logger logger = LoggerFactory.getLogger(AbstractMetricLogFilter.class);
- private final String partnerName;
- private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN");
public AbstractMetricLogFilter() {
- partnerName = getPartnerName();
+ super();
}
protected abstract void addHeader(RequestHeaders requestHeaders, String headerName, String headerValue);
- protected abstract String getTargetServiceName(Request request);
-
- protected abstract int getHttpStatusCode(Response response);
-
- protected abstract String getResponseCode(Response response);
-
- protected abstract String getTargetEntity(Request request);
-
protected void pre(Request request, RequestHeaders requestHeaders) {
try {
setupMDC(request);
- setupHeaders(request, requestHeaders);
+ setupHeaders(request, requestHeaders, extractRequestID(), setInvocationId());
+ additionalPre(request);
additionalPre(request, requestHeaders);
- logger.info(ONAPLogConstants.Markers.INVOKE, "Invoke");
+ logRequest();
} catch (Exception e) {
logger.warn("Error in AbstractMetricLogFilter pre", e);
}
@@ -65,71 +50,15 @@ public abstract class AbstractMetricLogFilter<Request, Response, RequestHeaders>
// override to add application specific logic
}
- protected void setupHeaders(Request clientRequest, RequestHeaders requestHeaders) {
- String requestId = extractRequestID();
- String invocationId = UUID.randomUUID().toString();
+ protected void setupHeaders(Request clientRequest, RequestHeaders requestHeaders, String requestId,
+ String invocationId) {
addHeader(requestHeaders, ONAPLogConstants.Headers.REQUEST_ID, requestId);
addHeader(requestHeaders, Constants.HttpHeaders.HEADER_REQUEST_ID, requestId);
addHeader(requestHeaders, Constants.HttpHeaders.TRANSACTION_ID, requestId);
addHeader(requestHeaders, Constants.HttpHeaders.ECOMP_REQUEST_ID, requestId);
addHeader(requestHeaders, ONAPLogConstants.Headers.PARTNER_NAME, partnerName);
- logger.info("Setting X-InvocationID header for outgoing request: {}", invocationId);
+ logger.trace("Setting X-InvocationID header for outgoing request: {}", invocationId);
addHeader(requestHeaders, ONAPLogConstants.Headers.INVOCATION_ID, invocationId);
-
- }
-
- protected void setupMDC(Request request) {
- MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP,
- ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
- MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, getTargetServiceName(request));
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
- setInvocationIdFromMDC();
-
- if (MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY) == null) {
- String targetEntity = getTargetEntity(request);
- if (targetEntity != null) {
- MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, targetEntity);
- } else {
- MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, Constants.DefaultValues.UNKNOWN_TARGET_ENTITY);
- }
- }
- setServerFQDN();
- }
-
- protected String extractRequestID() {
- String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
- if (requestId == null || requestId.isEmpty()) {
- requestId = UUID.randomUUID().toString();
- setLogTimestamp();
- setElapsedTimeInvokeTimestamp();
- logger.warn("No value found in MDC when checking key {} value will be set to {}",
- ONAPLogConstants.MDCs.REQUEST_ID, requestId);
- MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
- }
- return requestId;
- }
-
- protected void post(Request request, Response response) {
- try {
- setLogTimestamp();
- setElapsedTimeInvokeTimestamp();
- setResponseStatusCode(getHttpStatusCode(response));
- setResponseDescription(getHttpStatusCode(response));
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, getResponseCode(response));
- additionalPost(request, response);
- logger.info(INVOKE_RETURN, "InvokeReturn");
- clearClientMDCs();
- } catch (Exception e) {
- logger.warn("Error in AbstractMetricLogFilter post", e);
- }
- }
-
- protected void additionalPost(Request request, Response response) {
- // override to add application specific logic
- }
-
- protected String getPartnerName() {
- return getProperty(Constants.Property.PARTNER_NAME);
}
}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java
index 4783e7b..30f6d62 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java
@@ -27,6 +27,7 @@ import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.container.PreMatching;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;
import javax.ws.rs.ext.Providers;
@@ -36,6 +37,7 @@ import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
@Priority(1)
+@PreMatching
@Provider
public class AuditLogContainerFilter extends AbstractAuditLogFilter<ContainerRequestContext, ContainerResponseContext>
implements ContainerRequestFilter, ContainerResponseFilter {
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java
index be28f0b..2da32e1 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java
@@ -35,7 +35,6 @@ public class Constants {
public static final String TRANSACTION_ID = "X-TransactionID";
public static final String ECOMP_REQUEST_ID = "X-ECOMP-RequestID";
public static final String ONAP_REQUEST_ID = "X-ONAP-RequestID";
- public static final String CLIENT_ID = "X-ClientID";
public static final String INVOCATION_ID_HEADER = "X-InvocationID";
public static final String TARGET_ENTITY_HEADER = "X-Target-Entity";
}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomFilter.java
new file mode 100644
index 0000000..35379d2
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomFilter.java
@@ -0,0 +1,25 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+public interface CustomFilter<Request, Response> {
+ Boolean shouldLog(Request req, Response resp);
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomResponseStatus.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomResponseStatus.java
new file mode 100644
index 0000000..91626bb
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomResponseStatus.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+public enum CustomResponseStatus {
+ PROCESSING(102, "Processing"),
+ MULTI_STATUS(207, "Multi-Status"),
+ ALREADY_REPORTED(208, "Already Reported"),
+ UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"),
+ LOCKED(423, "Locked"),
+ FAILED_DEPENDENCY(424, "Failed Dependency"),
+ INSUFFICIENT_STORAGE(508, "Insufficient Storage"),
+ LOOP_DETECTED(508, "Loop Detected");
+
+ private final int code;
+ private final String reason;
+
+ CustomResponseStatus(int statusCode, String reasonPhrase) {
+ this.code = statusCode;
+ this.reason = reasonPhrase;
+ }
+
+ public static CustomResponseStatus fromStatusCode(int statusCode) {
+ for (CustomResponseStatus s : values()) {
+ if (s.code == statusCode) {
+ return s;
+ }
+ }
+
+ return null;
+ }
+
+ public int getStatusCode() {
+ return this.code;
+ }
+
+ public String getReasonPhrase() {
+ return this.toString();
+ }
+
+ public String toString() {
+ return this.reason;
+ }
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ErrorCode.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ErrorCode.java
new file mode 100644
index 0000000..3935ccd
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ErrorCode.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+public enum ErrorCode {
+ PermissionError(100),
+ AvailabilityError(200),
+ DataError(300),
+ SchemaError(400),
+ BusinessProcessError(500),
+ UnknownError(900);
+
+ private int value;
+
+ ErrorCode(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return this.value;
+ }
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/FilteredMetricLogClientFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/FilteredMetricLogClientFilter.java
new file mode 100644
index 0000000..0e5efae
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/FilteredMetricLogClientFilter.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+import java.util.Map;
+
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientResponseContext;
+
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.MDC;
+
+public class FilteredMetricLogClientFilter extends MetricLogClientFilter {
+ protected CustomFilter<ClientRequestContext, ClientResponseContext> customFilter;
+ private static final String REQUEST_STATE_PROPERTY_NAME = "org.onap.logging.filter.base.RequestState";
+
+ public FilteredMetricLogClientFilter(CustomFilter<ClientRequestContext, ClientResponseContext> f) {
+ customFilter = f;
+ }
+
+ protected void additionalPre(ClientRequestContext request) {
+ request.setProperty(REQUEST_STATE_PROPERTY_NAME, MDC.getCopyOfContextMap());
+ }
+
+ protected void additionalPost(ClientRequestContext request, ClientResponseContext response) {
+ if (customFilter.shouldLog(request, response)) {
+ Map<String, String> responseState = MDC.getCopyOfContextMap();
+ Map<String, String> requestState = (Map<String, String>) request.getProperty(REQUEST_STATE_PROPERTY_NAME);
+ MDC.setContextMap(requestState);
+ logger.info(ONAPLogConstants.Markers.INVOKE, "Invoke");
+ MDC.setContextMap(responseState);
+ logger.info(INVOKE_RETURN, "InvokeReturn");
+ }
+ }
+
+ protected void logRequest() {
+ // override with empty so log entries are not duplicated
+ }
+
+ protected void logResponse() {
+ // override with empty so log entries are not duplicated
+ }
+
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/HttpURLConnectionMetricUtil.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/HttpURLConnectionMetricUtil.java
index 3784538..39274fc 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/HttpURLConnectionMetricUtil.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/HttpURLConnectionMetricUtil.java
@@ -67,14 +67,6 @@ public class HttpURLConnectionMetricUtil
return Constants.DefaultValues.UNKNOWN_TARGET_ENTITY;
}
- public void pre(HttpURLConnection request) {
- pre(request, null);
- }
-
- public void filter(HttpURLConnection request, HttpURLConnection response) {
- post(request, response);
- }
-
@Override
protected void addHeader(HttpURLConnection request, String headerName, String headerValue) {
request.setRequestProperty(headerName, headerValue);
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java
index a900968..a90f053 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java
@@ -25,6 +25,7 @@ import java.net.UnknownHostException;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoUnit;
import java.util.Base64;
import java.util.UUID;
@@ -39,25 +40,70 @@ import org.slf4j.MDC;
public class MDCSetup {
protected static Logger logger = LoggerFactory.getLogger(MDCSetup.class);
-
private static final String INSTANCE_UUID = UUID.randomUUID().toString();
+ protected static final String serverIpAddressOverride = "SERVER_IP_ADDRESS_OVERRIDE";
+ protected static final String serverFqdnOverride = "SERVER_FQDN_OVERRIDE";
+ protected static final String INSTANT_PRECISION_OVERRIDE = "INSTANT_PRECISION_OVERRIDE";
+ protected static final String checkHeaderLogPattern = "Checking {} header to determine the value of {}";
+ protected String serverFqdn;
+ protected String serverIpAddress;
+ protected String[] prioritizedIdHeadersNames;
+ protected String[] prioritizedPartnerHeadersNames;
+ protected DateTimeFormatter iso8601Formatter;
+
+ public MDCSetup() {
+ this.prioritizedIdHeadersNames =
+ new String[] {ONAPLogConstants.Headers.REQUEST_ID, Constants.HttpHeaders.HEADER_REQUEST_ID,
+ Constants.HttpHeaders.TRANSACTION_ID, Constants.HttpHeaders.ECOMP_REQUEST_ID};
+ this.prioritizedPartnerHeadersNames =
+ new String[] {HttpHeaders.AUTHORIZATION, ONAPLogConstants.Headers.PARTNER_NAME, HttpHeaders.USER_AGENT};
+ initServerFqdnandIp();
+ this.iso8601Formatter = createFormatter();
+ }
+
+ protected String getCurrentTimeStamp() {
+ return ZonedDateTime.now(ZoneOffset.UTC).format(iso8601Formatter);
+ }
+
+ protected DateTimeFormatter createFormatter() {
+ DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
+ try {
+ Integer instantPrecision = Integer.valueOf(System.getProperty(INSTANT_PRECISION_OVERRIDE, "3"));
+ builder.appendInstant(instantPrecision);
+ } catch (NumberFormatException nfe) {
+ logger.warn("instant precision could not be read and thus won't be set, the default will be used instead."
+ + nfe.getMessage());
+ }
+ return builder.toFormatter();
+ }
public void setInstanceID() {
MDC.put(ONAPLogConstants.MDCs.INSTANCE_UUID, INSTANCE_UUID);
}
- public void setServerFQDN() {
- String serverFQDN = "";
- InetAddress addr = null;
- try {
- addr = InetAddress.getLocalHost();
- serverFQDN = addr.getCanonicalHostName();
- MDC.put(ONAPLogConstants.MDCs.SERVER_IP_ADDRESS, addr.getHostAddress());
- } catch (UnknownHostException e) {
- logger.warn("Cannot Resolve Host Name");
- serverFQDN = "";
+ protected void initServerFqdnandIp() {
+ serverFqdn = getProperty(serverFqdnOverride);
+ serverIpAddress = getProperty(serverIpAddressOverride);
+
+ if (serverIpAddress.equals(Constants.DefaultValues.UNKNOWN)
+ || serverFqdn.equals(Constants.DefaultValues.UNKNOWN)) {
+ try {
+ InetAddress addr = InetAddress.getLocalHost();
+ if (serverFqdn.equals(Constants.DefaultValues.UNKNOWN)) {
+ serverFqdn = addr.getCanonicalHostName();
+ }
+ if (serverIpAddress.equals(Constants.DefaultValues.UNKNOWN)) {
+ serverIpAddress = addr.getHostAddress();
+ }
+ } catch (UnknownHostException e) {
+ logger.trace("Cannot Resolve Host Name." + e.getMessage());
+ }
}
- MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFQDN);
+ }
+
+ public void setServerFQDN() {
+ MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFqdn);
+ MDC.put(ONAPLogConstants.MDCs.SERVER_IP_ADDRESS, serverIpAddress);
}
public void setClientIPAddress(HttpServletRequest httpServletRequest) {
@@ -76,35 +122,18 @@ public class MDCSetup {
}
public void setEntryTimeStamp() {
- MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP,
- ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
+ MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, getCurrentTimeStamp());
}
public String getRequestId(SimpleMap headers) {
- logger.trace("Checking X-ONAP-RequestID header for requestId.");
- String requestId = headers.get(ONAPLogConstants.Headers.REQUEST_ID);
- if (requestId != null && !requestId.isEmpty()) {
- return requestId;
- }
-
- logger.trace("No valid X-ONAP-RequestID header value. Checking X-RequestID header for requestId.");
- requestId = headers.get(Constants.HttpHeaders.HEADER_REQUEST_ID);
- if (requestId != null && !requestId.isEmpty()) {
- return requestId;
- }
-
- logger.trace("No valid X-RequestID header value. Checking X-TransactionID header for requestId.");
- requestId = headers.get(Constants.HttpHeaders.TRANSACTION_ID);
- if (requestId != null && !requestId.isEmpty()) {
- return requestId;
- }
-
- logger.trace("No valid X-TransactionID header value. Checking X-ECOMP-RequestID header for requestId.");
- requestId = headers.get(Constants.HttpHeaders.ECOMP_REQUEST_ID);
- if (requestId != null && !requestId.isEmpty()) {
- return requestId;
+ String requestId = null;
+ for (String headerName : this.prioritizedIdHeadersNames) {
+ logger.trace(checkHeaderLogPattern, headerName, ONAPLogConstants.Headers.REQUEST_ID);
+ requestId = headers.get(headerName);
+ if (requestId != null && !requestId.isEmpty()) {
+ return requestId;
+ }
}
-
logger.trace("No valid requestId headers. Generating requestId: {}", requestId);
return UUID.randomUUID().toString();
}
@@ -113,13 +142,7 @@ public class MDCSetup {
String invocationId = headers.get(ONAPLogConstants.Headers.INVOCATION_ID);
if (invocationId == null || invocationId.isEmpty())
invocationId = UUID.randomUUID().toString();
- MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
- }
-
- public void setInvocationIdFromMDC() {
- String invocationId = MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID);
- if (invocationId == null || invocationId.isEmpty())
- invocationId = UUID.randomUUID().toString();
+ MDC.put(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID, invocationId);
MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
}
@@ -129,40 +152,26 @@ public class MDCSetup {
}
protected String getMDCPartnerName(SimpleMap headers) {
- String checkHeaderLogPattern = "Checking {} header to determine the value of {}";
-
- logger.trace(checkHeaderLogPattern, HttpHeaders.AUTHORIZATION, ONAPLogConstants.MDCs.PARTNER_NAME);
- String partnerName = getBasicAuthUserName(headers);
- if (partnerName != null && !partnerName.isEmpty()) {
- return partnerName;
- }
-
- logger.trace(checkHeaderLogPattern, ONAPLogConstants.Headers.PARTNER_NAME, ONAPLogConstants.MDCs.PARTNER_NAME);
- partnerName = headers.get(ONAPLogConstants.Headers.PARTNER_NAME);
- if (partnerName != null && !partnerName.isEmpty()) {
- return partnerName;
- }
-
- logger.trace(checkHeaderLogPattern, HttpHeaders.USER_AGENT, ONAPLogConstants.MDCs.PARTNER_NAME);
- partnerName = headers.get(HttpHeaders.USER_AGENT);
- if (partnerName != null && !partnerName.isEmpty()) {
- return partnerName;
- }
+ String partnerName = null;
+ for (String headerName : prioritizedPartnerHeadersNames) {
+ logger.trace(checkHeaderLogPattern, headerName, ONAPLogConstants.MDCs.PARTNER_NAME);
+ if (headerName.equals(HttpHeaders.AUTHORIZATION)) {
+ partnerName = getBasicAuthUserName(headers);
+ } else {
+ partnerName = headers.get(headerName);
+ }
+ if (partnerName != null && !partnerName.isEmpty()) {
+ return partnerName;
+ }
- logger.trace(checkHeaderLogPattern, Constants.HttpHeaders.CLIENT_ID, ONAPLogConstants.MDCs.PARTNER_NAME);
- partnerName = headers.get(Constants.HttpHeaders.CLIENT_ID);
- if (partnerName != null && !partnerName.isEmpty()) {
- return partnerName;
}
-
logger.trace("{} value could not be determined, defaulting partnerName to {}.",
ONAPLogConstants.MDCs.PARTNER_NAME, Constants.DefaultValues.UNKNOWN);
return Constants.DefaultValues.UNKNOWN;
}
public void setLogTimestamp() {
- MDC.put(ONAPLogConstants.MDCs.LOG_TIMESTAMP,
- ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
+ MDC.put(ONAPLogConstants.MDCs.LOG_TIMESTAMP, getCurrentTimeStamp());
}
public void setElapsedTime() {
@@ -176,7 +185,7 @@ public class MDCSetup {
MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME,
Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp)));
} catch (Exception e) {
- logger.warn("Unable to calculate elapsed time due to error: {}", e.getMessage());
+ logger.trace("Unable to calculate elapsed time due to error: {}", e.getMessage());
}
}
@@ -191,7 +200,7 @@ public class MDCSetup {
MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME,
Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp)));
} catch (Exception e) {
- logger.warn("Unable to calculate elapsed time due to error: {}", e.getMessage());
+ logger.trace("Unable to calculate elapsed time due to error: {}", e.getMessage());
}
}
@@ -202,7 +211,7 @@ public class MDCSetup {
} else {
statusCode = ONAPLogConstants.ResponseStatus.ERROR.toString();
setErrorCode(code);
- setErrorDesc(code);
+ setErrorDescription(code);
}
MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, statusCode);
}
@@ -212,7 +221,7 @@ public class MDCSetup {
}
public void clearClientMDCs() {
- MDC.remove(ONAPLogConstants.MDCs.INVOCATION_ID);
+ MDC.remove(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID);
MDC.remove(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION);
MDC.remove(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE);
MDC.remove(ONAPLogConstants.MDCs.RESPONSE_CODE);
@@ -224,15 +233,27 @@ public class MDCSetup {
}
public void setResponseDescription(int statusCode) {
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, Response.Status.fromStatusCode(statusCode).toString());
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, extractDescription(statusCode));
+ }
+
+ private String extractDescription(int statusCode) {
+ Response.Status responseStatus = Response.Status.fromStatusCode(statusCode);
+ if (responseStatus != null) {
+ return responseStatus.toString();
+ }
+ CustomResponseStatus customResponseStatus = CustomResponseStatus.fromStatusCode(statusCode);
+ if (customResponseStatus != null) {
+ return customResponseStatus.toString();
+ }
+ return String.format("Unknown description for response code %d.", statusCode);
}
public void setErrorCode(int statusCode) {
MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, String.valueOf(statusCode));
}
- public void setErrorDesc(int statusCode) {
- MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, Response.Status.fromStatusCode(statusCode).toString());
+ public void setErrorDescription(int statusCode) {
+ MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, extractDescription(statusCode));
}
public String getProperty(String property) {
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java
index 0c0f5c4..fd954b7 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java
@@ -22,18 +22,52 @@
package org.onap.logging.filter.base;
-import javax.servlet.*;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.util.zip.GZIPInputStream;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ReadListener;
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.WriteListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
-import java.io.*;
-import java.util.zip.GZIPInputStream;
public class PayloadLoggingServletFilter extends AbstractServletFilter implements Filter {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(PayloadLoggingServletFilter.class);
+ private static final int defaultMaxSize = 100000;
+ private static Integer maxResponseSize;
+ private static Integer maxRequestSize;
+ protected static Boolean LOG_INVOKE;
+
+ public PayloadLoggingServletFilter() {
+ String maxRequestSizeOverride = System.getProperty("FILTER_MAX_REQUEST_SIZE");
+ if (maxRequestSizeOverride != null) {
+ maxRequestSize = Integer.valueOf(maxRequestSizeOverride);
+ } else {
+ maxRequestSize = defaultMaxSize;
+ }
+ String maxResponseSizeOverride = System.getProperty("FILTER_MAX_RESPONSE_SIZE");
+ if (maxResponseSizeOverride != null) {
+ maxResponseSize = Integer.valueOf(maxResponseSizeOverride);
+ } else {
+ maxResponseSize = defaultMaxSize;
+ }
+ }
private static class ByteArrayServletStream extends ServletOutputStream {
ByteArrayOutputStream baos;
@@ -194,7 +228,13 @@ public class PayloadLoggingServletFilter extends AbstractServletFilter implement
requestHeaders.append(getSecureRequestHeaders(httpRequest));
log.info(requestHeaders.toString());
- log.info("REQUEST BODY|{}", new String(bufferedRequest.getBuffer()));
+
+ byte[] buffer = bufferedRequest.getBuffer();
+ if (buffer.length < maxRequestSize) {
+ log.info("REQUEST BODY|{}", new String(buffer));
+ } else {
+ log.info("REQUEST BODY|{}", new String(buffer, 0, maxRequestSize));
+ }
final HttpServletResponse response = (HttpServletResponse) servletResponse;
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -242,7 +282,11 @@ public class PayloadLoggingServletFilter extends AbstractServletFilter implement
if ("gzip".equals(response.getHeader("Content-Encoding"))) {
log.info("UNGZIPED RESPONSE BODY|{}", decompressGZIPByteArray(bytes));
} else {
- log.info("RESPONSE BODY|{}", new String(bytes));
+ if (bytes.length < maxResponseSize) {
+ log.info("RESPONSE BODY|{}", new String(bytes));
+ } else {
+ log.info("RESPONSE BODY|{}", new String(bytes, 0, maxResponseSize));
+ }
}
if (pw.hasErrored()) {
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledLogging.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledLogging.java
new file mode 100644
index 0000000..39e5653
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledLogging.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.RetentionPolicy;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ScheduledLogging {
+
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTaskException.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTaskException.java
new file mode 100644
index 0000000..499d452
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTaskException.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+public class ScheduledTaskException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+ private ErrorCode errorCode;
+
+ public ScheduledTaskException(ErrorCode errorCode, String errorMessage, Throwable cause) {
+ super(errorMessage, cause);
+ this.setErrorCode(errorCode);
+ }
+
+ public ScheduledTaskException(ErrorCode errorCode, String errorMessage) {
+ super(errorMessage);
+ this.setErrorCode(errorCode);
+ }
+
+ public ErrorCode getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(ErrorCode errorCode) {
+ this.errorCode = errorCode;
+ }
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspect.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspect.java
new file mode 100644
index 0000000..74642b1
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspect.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.onap.logging.filter.base.AbstractMDCSetupAspect;
+import org.onap.logging.filter.base.ScheduledTaskException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Aspect
+public class ScheduledTasksMDCSetupAspect extends AbstractMDCSetupAspect {
+
+ protected static Logger logger = LoggerFactory.getLogger(ScheduledTasksMDCSetupAspect.class);
+
+ @Around("@annotation(ScheduledLogging)")
+ public void logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
+ setupMDC(joinPoint.getSignature().getName());
+ try {
+ joinPoint.proceed();
+ } catch (ScheduledTaskException e) {
+ errorMDCSetup(e.getErrorCode(), e.getMessage());
+ logger.error("ScheduledTaskException: ", e);
+ }
+ exitAndClearMDC();
+ }
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/SoapMetricLogHandler.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/SoapMetricLogHandler.java
new file mode 100644
index 0000000..088c28f
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/SoapMetricLogHandler.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+public class SoapMetricLogHandler extends AbstractBaseMetricLogFilter<SOAPMessageContext, SOAPMessageContext>
+ implements SOAPHandler<SOAPMessageContext> {
+
+ @Override
+ protected int getHttpStatusCode(SOAPMessageContext ctx) {
+ return (Integer) ctx.get(MessageContext.HTTP_RESPONSE_CODE);
+ }
+
+ @Override
+ protected String getResponseCode(SOAPMessageContext ctx) {
+ Integer responseCode = (Integer) ctx.get(MessageContext.HTTP_RESPONSE_CODE);
+ return String.valueOf(responseCode);
+ }
+
+ @Override
+ protected String getTargetEntity(SOAPMessageContext ctx) {
+ return Constants.DefaultValues.UNKNOWN_TARGET_ENTITY;
+ }
+
+ @Override
+ protected String getTargetServiceName(SOAPMessageContext ctx) {
+ QName svc = (QName) ctx.get(SOAPMessageContext.WSDL_SERVICE);
+ QName op = (QName) ctx.get(SOAPMessageContext.WSDL_OPERATION);
+ return svc.getLocalPart() + ":" + op.getLocalPart();
+ }
+
+ @Override
+ public void close(MessageContext context) {
+ // pass
+ }
+
+ @Override
+ public boolean handleFault(SOAPMessageContext context) {
+ logMessage(context);
+ return true;
+ }
+
+ @Override
+ public boolean handleMessage(SOAPMessageContext context) {
+ logMessage(context);
+ return true;
+ }
+
+ @Override
+ public Set<QName> getHeaders() {
+ return null;
+ }
+
+ private void logMessage(SOAPMessageContext context) {
+ boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ if (outbound) {
+ this.pre(context);
+ } else {
+ this.post(context, context);
+ }
+ }
+
+}
diff --git a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java
index bdf8bd0..fb6ca71 100644
--- a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java
+++ b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java
@@ -24,6 +24,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
+
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.HttpHeaders;
@@ -116,6 +119,7 @@ public class MDCSetupTest extends MDCSetup {
HashMap<String, String> headers = new HashMap<>();
headers.put(ONAPLogConstants.Headers.INVOCATION_ID, invocationId);
setInvocationId(new SimpleHashMap(headers));
+ assertEquals(invocationId, MDC.get(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID));
assertEquals(invocationId, MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID));
}
@@ -123,20 +127,7 @@ public class MDCSetupTest extends MDCSetup {
public void setInvocationIdNoHeaderTest() {
HashMap<String, String> headers = new HashMap<>();
setInvocationId(new SimpleHashMap(headers));
- assertNotNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID));
- }
-
- @Test
- public void setInvovationIdFromMDCTest() {
- MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, "7b77143c-9b50-410c-ac2f-05758a68e3e8");
- setInvocationIdFromMDC();
- assertEquals("7b77143c-9b50-410c-ac2f-05758a68e3e8", MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID));
- }
-
- @Test
- public void setInvocationIdFromMDCNoInvocationIdTest() {
- setInvocationIdFromMDC();
- // InvocationId is set to a random UUID
+ assertNotNull(MDC.get(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID));
assertNotNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID));
}
@@ -156,7 +147,7 @@ public class MDCSetupTest extends MDCSetup {
@Test
public void clearClientMDCsTest() {
- MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, "7b77143c-9b50-410c-ac2f-05758a68e3e9");
+ MDC.put(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID, "7b77143c-9b50-410c-ac2f-05758a68e3e9");
MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, "Bad Gateway");
MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, "Bad Gateway");
MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, "502");
@@ -167,7 +158,7 @@ public class MDCSetupTest extends MDCSetup {
MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, "2019-06-18T02:09:06.024Z");
clearClientMDCs();
- assertNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID));
+ assertNull(MDC.get(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID));
assertNull(MDC.get(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION));
assertNull(MDC.get(ONAPLogConstants.MDCs.ERROR_CODE));
assertNull(MDC.get(ONAPLogConstants.MDCs.ERROR_DESC));
@@ -237,17 +228,6 @@ public class MDCSetupTest extends MDCSetup {
}
@Test
- public void setMDCPartnerNameClientIdHeaderTest() {
- MultivaluedMap<String, String> headerMap = new MultivaluedHashMap<>();
- headerMap.putSingle(Constants.HttpHeaders.CLIENT_ID, "SO");
- SimpleMap headers = new SimpleJaxrsHeadersMap(headerMap);
-
- setMDCPartnerName(headers);
-
- assertEquals("SO", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME));
- }
-
- @Test
public void setMDCPartnerNameNoHeaderTest() {
MultivaluedMap<String, String> headerMap = new MultivaluedHashMap<>();
SimpleMap headers = new SimpleJaxrsHeadersMap(headerMap);
@@ -322,4 +302,30 @@ public class MDCSetupTest extends MDCSetup {
assertEquals("UNKNOWN", partnerName);
}
+ @Test
+ public void overrideServerIp() {
+ String ip = "127.0.0.1";
+ System.setProperty(serverIpAddressOverride, ip);
+ MDCSetup m = new MDCSetup();
+ assertEquals(ip, m.serverIpAddress);
+ }
+
+ @Test
+ public void overrideServerFqdn() {
+ String nodeName = "node300";
+ System.setProperty(serverFqdnOverride, nodeName);
+ MDCSetup m = new MDCSetup();
+ assertEquals(nodeName, m.serverFqdn);
+ }
+
+ @Test
+ public void testPrecision() {
+ System.setProperty(MDCSetup.INSTANT_PRECISION_OVERRIDE, "3");
+ ZonedDateTime zdt = ZonedDateTime.now(ZoneOffset.UTC);
+ zdt = zdt.withNano(333666999);
+ MDCSetup m = new MDCSetup();
+ String currentTimestamp = m.getCurrentTimeStamp();
+ assertEquals(24, currentTimestamp.length());
+ }
+
}
diff --git a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java
index 3729e92..cfce542 100644
--- a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java
+++ b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java
@@ -57,11 +57,9 @@ public class MetricLogClientFilterTest {
@Test
public void setupHeadersTest() {
- MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, "8819bfb4-69d2-43fc-b0d6-81d2690533ea");
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
- doReturn("0a908a5d-e774-4558-96ff-6edcbba65483").when(metricLogClientFilter).extractRequestID();
- metricLogClientFilter.setupHeaders(clientRequest, headers);
+ metricLogClientFilter.setupHeaders(clientRequest, headers, "0a908a5d-e774-4558-96ff-6edcbba65483", "hello");
assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(ONAPLogConstants.Headers.REQUEST_ID));
assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(Constants.HttpHeaders.HEADER_REQUEST_ID));
@@ -73,6 +71,14 @@ public class MetricLogClientFilterTest {
}
@Test
+ public void setInvocationIdTest() {
+ String invocationId = metricLogClientFilter.setInvocationId();
+
+ assertEquals(invocationId, MDC.get(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID));
+ assertEquals(invocationId, MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID));
+ }
+
+ @Test
public void setupMDCTest() throws URISyntaxException {
// TODO ingest change from upstream
MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, "SO");
diff --git a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspectTest.java b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspectTest.java
new file mode 100644
index 0000000..bdd1033
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspectTest.java
@@ -0,0 +1,99 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.UUID;
+
+import org.junit.After;
+import org.junit.Test;
+import org.onap.logging.filter.base.Constants;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+
+import org.slf4j.MDC;
+
+public class ScheduledTasksMDCSetupAspectTest {
+
+ private ScheduledTasksMDCSetupAspect tasksMDCSetup = new ScheduledTasksMDCSetupAspect();
+
+ @After
+ public void tearDown() {
+ MDC.clear();
+ System.clearProperty("partnerName");
+ }
+
+ @Test
+ public void mdcSetupTest() {
+ System.setProperty("partnerName", ONAPComponents.SO.toString());
+ tasksMDCSetup.setupMDC("mdcSetupTest");
+
+ assertTrue(isValidUUID(MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)));
+ assertTrue(isValidUUID(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)));
+ assertEquals(ONAPComponents.SO.toString(), MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY));
+ assertEquals(ONAPComponents.SO.toString(), MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME));
+ assertEquals("mdcSetupTest", MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME));
+ assertEquals(Constants.DefaultValues.UNKNOWN, MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME));
+ assertNotNull(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
+ assertNotNull(MDC.get(ONAPLogConstants.MDCs.ELAPSED_TIME));
+ assertNotNull(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP));
+ assertNotNull(MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN));
+ }
+
+ @Test
+ public void errorMDCSetupTest() {
+ tasksMDCSetup.errorMDCSetup(ErrorCode.UnknownError, "Error");
+
+ assertEquals("900", MDC.get(ONAPLogConstants.MDCs.ERROR_CODE));
+ assertEquals("Error", MDC.get(ONAPLogConstants.MDCs.ERROR_DESC));
+ }
+
+ @Test
+ public void setStatusCodeTest() {
+ tasksMDCSetup.setStatusCode();
+
+ assertEquals(ONAPLogConstants.ResponseStatus.COMPLETE.toString(),
+ MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
+ }
+
+ @Test
+ public void setStatusCodeErrorTest() {
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.ERROR.toString());
+ tasksMDCSetup.setStatusCode();
+
+ assertEquals(ONAPLogConstants.ResponseStatus.ERROR.toString(),
+ MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
+ }
+
+ public static boolean isValidUUID(String id) {
+ try {
+ if (null == id) {
+ return false;
+ }
+ UUID uuid = UUID.fromString(id);
+ return uuid.toString().equalsIgnoreCase(id);
+ } catch (IllegalArgumentException iae) {
+ return false;
+ }
+ }
+}
diff --git a/reference/logging-filter/logging-filter-spring/pom.xml b/reference/logging-filter/logging-filter-spring/pom.xml
index f26ab69..97d3246 100644
--- a/reference/logging-filter/logging-filter-spring/pom.xml
+++ b/reference/logging-filter/logging-filter-spring/pom.xml
@@ -1,71 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-filter-parent</artifactId>
- <version>1.6.2-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-filter-parent</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
+ </parent>
- <artifactId>logging-filter-spring</artifactId>
+ <artifactId>logging-filter-spring</artifactId>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-dependencies</artifactId>
- <version>2.0.5.RELEASE</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-webmvc</artifactId>
- </dependency>
- <dependency>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-filter-base</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-slf4j</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.ws.rs</groupId>
- <artifactId>javax.ws.rs-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-client</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <name>logging-analytics :: ${project.artifactId}</name>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>2.0.5.RELEASE</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-filter-base</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-slf4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
diff --git a/reference/logging-filter/logging-filter-spring/src/main/java/org/onap/logging/filter/spring/SpringScheduledTasksMDCSetupAspect.java b/reference/logging-filter/logging-filter-spring/src/main/java/org/onap/logging/filter/spring/SpringScheduledTasksMDCSetupAspect.java
new file mode 100644
index 0000000..24d9014
--- /dev/null
+++ b/reference/logging-filter/logging-filter-spring/src/main/java/org/onap/logging/filter/spring/SpringScheduledTasksMDCSetupAspect.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.spring;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.onap.logging.filter.base.AbstractMDCSetupAspect;
+import org.onap.logging.filter.base.ScheduledTaskException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Aspect
+@Component
+public class SpringScheduledTasksMDCSetupAspect extends AbstractMDCSetupAspect {
+
+ protected static Logger logger = LoggerFactory.getLogger(SpringScheduledTasksMDCSetupAspect.class);
+
+ @Around("@annotation(org.onap.logging.filter.base.ScheduledLogging)")
+ public void logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
+ setupMDC(joinPoint.getSignature().getName());
+ try {
+ joinPoint.proceed();
+ } catch (ScheduledTaskException e) {
+ errorMDCSetup(e.getErrorCode(), e.getMessage());
+ logger.error("ScheduledTaskException: ", e);
+ }
+ exitAndClearMDC();
+ }
+}
diff --git a/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java b/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java
index c9925eb..ea54345 100644
--- a/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java
+++ b/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java
@@ -120,11 +120,9 @@ public class SpringClientFilterTest extends SpringClientFilter {
@Test
public void setupHeadersTest() {
- MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, "8819bfb4-69d2-43fc-b0d6-81d2690533ea");
- MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, "0a908a5d-e774-4558-96ff-6edcbba65483");
-
HttpHeaders headers = new HttpHeaders();
- setupHeaders(clientRequest, headers);
+ setupHeaders(clientRequest, headers, "0a908a5d-e774-4558-96ff-6edcbba65483",
+ "4d93e6e2-ff27-4818-9752-1cfe3090d3f1");
assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(ONAPLogConstants.Headers.REQUEST_ID));
assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(Constants.HttpHeaders.HEADER_REQUEST_ID));
diff --git a/reference/logging-filter/pom.xml b/reference/logging-filter/pom.xml
index 27e6284..36e0fd0 100644
--- a/reference/logging-filter/pom.xml
+++ b/reference/logging-filter/pom.xml
@@ -1,263 +1,195 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-reference</artifactId>
- <version>1.6.2-SNAPSHOT</version>
- </parent>
-
- <artifactId>logging-filter-parent</artifactId>
- <packaging>pom</packaging>
+ <parent>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-reference</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
+ </parent>
- <modules>
- <module>logging-filter-base</module>
- <module>logging-filter-spring</module>
- </modules>
+ <artifactId>logging-filter-parent</artifactId>
+ <packaging>pom</packaging>
- <properties>
- <format.skipValidate>false</format.skipValidate>
- <format.skipExecute>true</format.skipExecute>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>javax.annotation</groupId>
- <artifactId>javax.annotation-api</artifactId>
- <version>1.2</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-slf4j</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.1.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.ws.rs</groupId>
- <artifactId>javax.ws.rs-api</artifactId>
- <version>2.0.1</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.25</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <version>2.11.2</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>2.15.0</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
+ <name>logging-analytics :: ${project.artifactId}</name>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.5.1</version>
- <executions>
- <execution>
- <id>default-compile</id>
- <phase>compile</phase>
- <goals>
- <goal>compile</goal>
- </goals>
- </execution>
- <execution>
- <id>default-testCompile</id>
- <phase>test-compile</phase>
- <goals>
- <goal>testCompile</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- <showWarnings>true</showWarnings>
- <compilerArgument>-parameters</compilerArgument>
- <compilerArgument>-Xlint:deprecation</compilerArgument>
- </configuration>
- </plugin>
+ <modules>
+ <module>logging-filter-base</module>
+ <module>logging-filter-spring</module>
+ </modules>
- <!-- Plugin to identify root path of the project -->
- <plugin>
- <groupId>org.commonjava.maven.plugins</groupId>
- <artifactId>directory-maven-plugin</artifactId>
- <version>0.2</version>
- <executions>
- <execution>
- <phase>validate</phase>
- <id>directories</id>
- <goals>
- <goal>highest-basedir</goal>
- </goals>
- <configuration>
- <property>baseDirPath</property>
- </configuration>
- </execution>
- </executions>
- </plugin>
+ <properties>
+ <format.skipValidate>false</format.skipValidate>
+ <format.skipExecute>true</format.skipExecute>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
- <!-- Plugin to Generate/Validate Copyright License header -->
- <!--
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>license-maven-plugin</artifactId>
- <version>1.20</version>
- <configuration>
- <processStartTag>============LICENSE_START=======================================================</processStartTag>
- <sectionDelimiter>================================================================================</sectionDelimiter>
- <processEndTag>============LICENSE_END=========================================================</processEndTag>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>1.9.5</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <version>1.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-slf4j</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <version>2.0.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.25</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <version>2.11.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
- <licenseName>apache_v2</licenseName>
- <inceptionYear>2019</inceptionYear>
- <organizationName>AT&amp;T Intellectual Property. All rights reserved.</organizationName>
- <projectName>ONAP - Logging</projectName>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <!-- Plugin to identify root path of the project -->
+ <plugin>
+ <groupId>org.commonjava.maven.plugins</groupId>
+ <artifactId>directory-maven-plugin</artifactId>
+ <version>0.2</version>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <id>directories</id>
+ <goals>
+ <goal>highest-basedir</goal>
+ </goals>
+ <configuration>
+ <property>baseDirPath</property>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
- <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
- <skipUpdateLicense>${format.skipExecute}</skipUpdateLicense>
- <skipCheckLicense>${format.skipValidate}</skipCheckLicense>
- </configuration>
- <executions>
- <execution>
- <id>update-headers</id>
- <goals>
- <goal>update-file-header</goal>
- </goals>
- <phase>process-sources</phase>
- <configuration>
- <canUpdateCopyright>true</canUpdateCopyright>
- <canUpdateDescription>true</canUpdateDescription>
- <canUpdateLicense>true</canUpdateLicense>
- <emptyLineAfterHeader>true</emptyLineAfterHeader>
- </configuration>
- </execution>
- <execution>
- <id>check-headers</id>
- <goals>
- <goal>check-file-header</goal>
- </goals>
- <phase>validate</phase>
- <configuration>
- <failOnNotUptodateHeader>true</failOnNotUptodateHeader>
- <failOnMissingHeader>true</failOnMissingHeader>
- </configuration>
- </execution>
- </executions>
- </plugin>
- -->
+ <!-- Plugin to Generate/Validate Copyright License header -->
+ <!-- <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>license-maven-plugin</artifactId> <version>1.20</version> <configuration> <processStartTag>============LICENSE_START=======================================================</processStartTag>
+ <sectionDelimiter>================================================================================</sectionDelimiter> <processEndTag>============LICENSE_END=========================================================</processEndTag>
+ <licenseName>apache_v2</licenseName> <inceptionYear>2019</inceptionYear> <organizationName>AT&amp;T Intellectual Property. All rights reserved.</organizationName> <projectName>ONAP
+ - Logging</projectName> <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage> <skipUpdateLicense>${format.skipExecute}</skipUpdateLicense> <skipCheckLicense>${format.skipValidate}</skipCheckLicense>
+ </configuration> <executions> <execution> <id>update-headers</id> <goals> <goal>update-file-header</goal> </goals> <phase>process-sources</phase> <configuration> <canUpdateCopyright>true</canUpdateCopyright>
+ <canUpdateDescription>true</canUpdateDescription> <canUpdateLicense>true</canUpdateLicense> <emptyLineAfterHeader>true</emptyLineAfterHeader> </configuration> </execution> <execution>
+ <id>check-headers</id> <goals> <goal>check-file-header</goal> </goals> <phase>validate</phase> <configuration> <failOnNotUptodateHeader>true</failOnNotUptodateHeader> <failOnMissingHeader>true</failOnMissingHeader>
+ </configuration> </execution> </executions> </plugin> -->
- <!-- Plugin to Format/Validate Java Classes -->
- <plugin>
- <groupId>net.revelc.code.formatter</groupId>
- <artifactId>formatter-maven-plugin</artifactId>
- <version>2.10.0</version>
- <executions>
- <execution>
- <id>format-java</id>
- <goals>
- <goal>format</goal>
- </goals>
- <phase>process-sources</phase>
- <configuration>
- <lineEnding>LF</lineEnding>
- <skip>${format.skipExecute}</skip>
- <sourceDirectory>${project.basedir}</sourceDirectory>
- <configFile>${baseDirPath}/project-configs/code-tools/onap-java-format.xml</configFile>
- <includes>
- <include>src/**/*.java</include>
- </includes>
- </configuration>
- </execution>
- <execution>
- <id>validate-java</id>
- <goals>
- <goal>validate</goal>
- </goals>
- <phase>validate</phase>
- <configuration>
- <lineEnding>LF</lineEnding>
- <skip>${format.skipValidate}</skip>
- <sourceDirectory>${project.basedir}</sourceDirectory>
- <configFile>${baseDirPath}/project-configs/code-tools/onap-java-format.xml</configFile>
- <includes>
- <include>src/**/*.java</include>
- </includes>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- <version>2.9.8</version>
- </dependency>
- </dependencies>
- </plugin>
+ <!-- Plugin to Format/Validate Java Classes -->
+ <plugin>
+ <groupId>net.revelc.code.formatter</groupId>
+ <artifactId>formatter-maven-plugin</artifactId>
+ <version>2.10.0</version>
+ <executions>
+ <execution>
+ <id>format-java</id>
+ <goals>
+ <goal>format</goal>
+ </goals>
+ <phase>process-sources</phase>
+ <configuration>
+ <lineEnding>LF</lineEnding>
+ <skip>${format.skipExecute}</skip>
+ <sourceDirectory>${project.basedir}</sourceDirectory>
+ <configFile>${baseDirPath}/project-configs/code-tools/onap-java-format.xml</configFile>
+ <includes>
+ <include>src/**/*.java</include>
+ </includes>
+ </configuration>
+ </execution>
+ <execution>
+ <id>validate-java</id>
+ <goals>
+ <goal>validate</goal>
+ </goals>
+ <phase>validate</phase>
+ <configuration>
+ <lineEnding>LF</lineEnding>
+ <skip>${format.skipValidate}</skip>
+ <sourceDirectory>${project.basedir}</sourceDirectory>
+ <configFile>${baseDirPath}/project-configs/code-tools/onap-java-format.xml</configFile>
+ <includes>
+ <include>src/**/*.java</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>2.9.8</version>
+ </dependency>
+ </dependencies>
+ </plugin>
- <!-- Plugin to Format/Validate POM Files -->
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>tidy-maven-plugin</artifactId>
- <version>1.1.0</version>
- <executions>
- <execution>
- <id>format-pom</id>
- <phase>process-sources</phase>
- <goals>
- <goal>pom</goal>
- </goals>
- <configuration>
- <skip>${format.skipExecute}</skip>
- </configuration>
- </execution>
- <execution>
- <id>validate-pom</id>
- <phase>validate</phase>
- <goals>
- <goal>check</goal>
- </goals>
- <configuration>
- <skip>${format.skipValidate}</skip>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <!-- Plugin to Format/Validate POM Files -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>tidy-maven-plugin</artifactId>
+ <version>1.1.0</version>
+ <executions>
+ <execution>
+ <id>format-pom</id>
+ <phase>process-sources</phase>
+ <goals>
+ <goal>pom</goal>
+ </goals>
+ <configuration>
+ <skip>${format.skipExecute}</skip>
+ </configuration>
+ </execution>
+ <execution>
+ <id>validate-pom</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <configuration>
+ <skip>${format.skipValidate}</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
- <profiles>
- <profile>
- <id>format</id>
- <properties>
- <format.skipValidate>true</format.skipValidate>
- <format.skipExecute>false</format.skipExecute>
- </properties>
- </profile>
- </profiles>
+ <profiles>
+ <profile>
+ <id>format</id>
+ <properties>
+ <format.skipValidate>true</format.skipValidate>
+ <format.skipExecute>false</format.skipExecute>
+ </properties>
+ </profile>
+ </profiles>
</project>
diff --git a/reference/logging-kubernetes/.project b/reference/logging-kubernetes/.project
deleted file mode 100644
index a7ec855..0000000
--- a/reference/logging-kubernetes/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>logging-kubernetes</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- </natures>
-</projectDescription>
diff --git a/reference/logging-kubernetes/pom.xml b/reference/logging-kubernetes/pom.xml
index 459d03e..ef40370 100644
--- a/reference/logging-kubernetes/pom.xml
+++ b/reference/logging-kubernetes/pom.xml
@@ -1,12 +1,15 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
<parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-reference</artifactId>
- <version>1.6.2-SNAPSHOT</version>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-reference</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
</parent>
+
<artifactId>logging-kubernetes</artifactId>
<packaging>pom</packaging>
- <name>logging-kubernetes</name>
+
+ <name>logging-analytics :: ${project.artifactId}</name>
</project>
diff --git a/reference/logging-library/.classpath b/reference/logging-library/.classpath
deleted file mode 100644
index 7a80cdf..0000000
--- a/reference/logging-library/.classpath
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- <attribute name="org.eclipse.jst.component.nondependency" value=""/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
diff --git a/reference/logging-library/.gitignore b/reference/logging-library/.gitignore
deleted file mode 100644
index 99d2bb1..0000000
--- a/reference/logging-library/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/target/
-/build/
diff --git a/reference/logging-library/.project b/reference/logging-library/.project
deleted file mode 100644
index 5ffa62b..0000000
--- a/reference/logging-library/.project
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>logging-library</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.common.project.facet.core.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.springframework.ide.eclipse.core.springbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
- <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
- <nature>org.springframework.ide.eclipse.core.springnature</nature>
- <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/reference/logging-library/pom.xml b/reference/logging-library/pom.xml
index 260ba13..a7b7ba2 100644
--- a/reference/logging-library/pom.xml
+++ b/reference/logging-library/pom.xml
@@ -1,144 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
<parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-reference</artifactId>
- <version>1.6.2-SNAPSHOT</version>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-reference</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
</parent>
+
<artifactId>logging-library</artifactId>
<packaging>jar</packaging>
- <name>logging-library</name>
+
+ <name>logging-analytics :: ${project.artifactId}</name>
+
<properties>
- <spring.version>5.1.2.RELEASE</spring.version>
- <logback.version>1.2.3</logback.version>
+ <spring.version>5.1.2.RELEASE</spring.version>
+ <logback.version>1.2.3</logback.version>
</properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-slf4j</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- decouple HttpServlet parameters from both this project and slf4j later -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.0.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-orm</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-oxm</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ <!--scope>test</scope -->
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aspects</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>1.9.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
+ </dependencies>
+
<build>
- <plugins>
+ <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.2</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
</plugin>
</plugins>
- <pluginManagement>
- <plugins>
- <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
- <plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>
- org.apache.maven.plugins
- </groupId>
- <artifactId>
- maven-compiler-plugin
- </artifactId>
- <versionRange>
- [3.2,)
- </versionRange>
- <goals>
- <goal>testCompile</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore></ignore>
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
</build>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-slf4j</artifactId>
- <version>${project.version}</version>
- </dependency>
- <!-- decouple HttpServlet parameters from both this project and slf4j later -->
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.0.1</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aop</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-orm</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-oxm</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>${spring.version}</version>
- <!--scope>test</scope-->
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aspects</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjrt</artifactId>
- <version>1.9.1</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-tx</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-webmvc</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- <version>${logback.version}</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>${logback.version}</version>
- </dependency>
- </dependencies>
</project>
diff --git a/reference/logging-mock-service/.classpath b/reference/logging-mock-service/.classpath
deleted file mode 100644
index f941705..0000000
--- a/reference/logging-mock-service/.classpath
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- <attribute name="org.eclipse.jst.component.nondependency" value=""/>
- </attributes>
- </classpathentry>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
diff --git a/reference/logging-mock-service/.gitignore b/reference/logging-mock-service/.gitignore
deleted file mode 100644
index 99d2bb1..0000000
--- a/reference/logging-mock-service/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/target/
-/build/
diff --git a/reference/logging-mock-service/.project b/reference/logging-mock-service/.project
deleted file mode 100644
index 8e8b873..0000000
--- a/reference/logging-mock-service/.project
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>logging-mock-service</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.common.project.facet.core.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.springframework.ide.eclipse.core.springbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
- <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
- <nature>org.springframework.ide.eclipse.core.springnature</nature>
- <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/reference/logging-mock-service/pom.xml b/reference/logging-mock-service/pom.xml
index 1751aee..1cdbf51 100644
--- a/reference/logging-mock-service/pom.xml
+++ b/reference/logging-mock-service/pom.xml
@@ -1,68 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
<parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-reference</artifactId>
- <version>1.6.2-SNAPSHOT</version>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-reference</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
</parent>
+
<artifactId>logging-mock-service</artifactId>
<packaging>jar</packaging>
- <name>logging-mock-service</name>
+
+ <name>logging-analytics :: ${project.artifactId}</name>
+
+ <properties>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-library</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
<build>
- <plugins>
+ <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.2</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
</plugin>
</plugins>
- <pluginManagement>
- <plugins>
- <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
- <plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>
- org.apache.maven.plugins
- </groupId>
- <artifactId>
- maven-compiler-plugin
- </artifactId>
- <versionRange>
- [3.2,)
- </versionRange>
- <goals>
- <goal>testCompile</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore></ignore>
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
</build>
- <properties>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-library</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
</project>
diff --git a/reference/logging-slf4j-demo/pom.xml b/reference/logging-slf4j-demo/pom.xml
index 9cbddd5..63830b6 100644
--- a/reference/logging-slf4j-demo/pom.xml
+++ b/reference/logging-slf4j-demo/pom.xml
@@ -1,169 +1,165 @@
+<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-reference</artifactId>
- <version>1.6.2-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>logging-slf4j-demo</artifactId>
- <name>logging-slf4j-demo</name>
- <packaging>war</packaging>
- <properties>
- <!-- from 1.5.10 to not pull in spring 4.3.14/5.0.5 override of 5.0.9
- however 4.3.17 of spring-core over 4.3.14 is not enough - need 4.3.18+
- tomcat-embed-core 8.5.31 needs 8.5.32+ - which spring-boot 1.5.15 brings in
- spring-expression 4.3.14 goes to 4.3.17 under 1.5.15
- 1.5.17 ups jackson-databind from 2.8.11.2 - but we will likely need 2.9+
- -->
- <springframework.boot.version>1.5.22.RELEASE</springframework.boot.version>
- <spring.version>5.1.2.RELEASE</spring.version>
- <logback.version>1.2.3</logback.version>
- </properties>
+ <modelVersion>4.0.0</modelVersion>
- <dependencies>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>logging-slf4j</artifactId>
- <version>1.4.0</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-json</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </dependency>
- <dependency>
- <groupId>com.mashape.unirest</groupId>
- <artifactId>unirest-java</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- </dependency>
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <parent>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-reference</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>logging-slf4j-demo</artifactId>
+ <packaging>war</packaging>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-dependencies</artifactId>
- <version>${springframework.boot.version}</version>
- <type>pom</type>
- <scope>import</scope>
- <exclusions>
- <exclusion>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-websocket</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.4</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.25</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>${logback.version}</version>
- </dependency>
- <dependency>
- <groupId>com.mashape.unirest</groupId>
- <artifactId>unirest-java</artifactId>
- <version>1.4.9</version>
- <exclusions>
- <exclusion>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <version>6.8.5</version>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <version>1.3</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>${spring.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
+ <name>logging-analytics :: ${project.artifactId}</name>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-war-plugin</artifactId>
- <configuration/>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.7.0</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <version>${springframework.boot.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>repackage</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <properties>
+ <!-- from 1.5.10 to not pull in spring 4.3.14/5.0.5 override of 5.0.9 however 4.3.17 of spring-core over 4.3.14 is not enough - need 4.3.18+ tomcat-embed-core 8.5.31 needs 8.5.32+
+ - which spring-boot 1.5.15 brings in spring-expression 4.3.14 goes to 4.3.17 under 1.5.15 1.5.17 ups jackson-databind from 2.8.11.2 - but we will likely need 2.9+ -->
+ <springframework.boot.version>1.5.22.RELEASE</springframework.boot.version>
+ <spring.version>5.1.2.RELEASE</spring.version>
+ <logback.version>1.2.3</logback.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${springframework.boot.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-websocket</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.25</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.mashape.unirest</groupId>
+ <artifactId>unirest-java</artifactId>
+ <version>1.4.9</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>6.8.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>logging-slf4j</artifactId>
+ <version>1.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-json</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.mashape.unirest</groupId>
+ <artifactId>unirest-java</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>3.2.3</version>
+ <configuration />
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${springframework.boot.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/reference/logging-slf4j/pom.xml b/reference/logging-slf4j/pom.xml
index 6a3a6f3..57a7107 100644
--- a/reference/logging-slf4j/pom.xml
+++ b/reference/logging-slf4j/pom.xml
@@ -1,92 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-reference</artifactId>
- <version>1.6.2-SNAPSHOT</version>
- </parent>
- <artifactId>logging-slf4j</artifactId>
- <name>logging-slf4j</name>
- <packaging>jar</packaging>
- <properties>
- <spring.version>5.0.9.RELEASE</spring.version>
- <logback.version>1.2.3</logback.version>
- </properties>
- <dependencies>
- <!-- Exported dependencies. -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <!-- Provided dependencies. -->
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <!-- Test dependencies. -->
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-reference</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>logging-slf4j</artifactId>
+ <packaging>jar</packaging>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.25</version>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.1.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>${logback.version}</version>
- </dependency>
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <version>6.8.5</version>
- <exclusions>
- <exclusion>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <version>1.3</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>${spring.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
+ <name>logging-analytics :: ${project.artifactId}</name>
+ <properties>
+ <spring.version>5.0.9.RELEASE</spring.version>
+ <logback.version>1.2.3</logback.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.25</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>6.8.5</version>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <!-- Compile dependencies. -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <!-- Provided dependencies. -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <!-- Test dependencies. -->
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
diff --git a/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java b/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java
index 5357f40..48681e5 100644
--- a/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java
+++ b/reference/logging-slf4j/src/main/java/org/onap/logging/ref/slf4j/ONAPLogConstants.java
@@ -102,6 +102,10 @@ public final class ONAPLogConstants {
/** MDC correlating messages for an invocation. */
public static final String INVOCATION_ID = "InvocationID";
+
+ public static final String SERVER_INVOCATION_ID = "ServerInvocationId";
+
+ public static final String CLIENT_INVOCATION_ID = "ClientInvocationId";
/** MDC correlating messages for a logical transaction. */
public static final String REQUEST_ID = "RequestID";
diff --git a/reference/pom.xml b/reference/pom.xml
index 61ea63e..068a3c2 100644
--- a/reference/pom.xml
+++ b/reference/pom.xml
@@ -1,15 +1,18 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
<parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-analytics</artifactId>
- <version>1.6.2-SNAPSHOT</version>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-analytics</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
</parent>
+
<artifactId>logging-reference</artifactId>
<packaging>pom</packaging>
- <name>logging-reference</name>
- <url>http://maven.apache.org</url>
+
+ <name>logging-analytics :: ${project.artifactId}</name>
+
<modules>
<module>logging-demo</module>
<module>logging-library</module>
@@ -19,110 +22,83 @@
<module>logging-slf4j</module>
<module>logging-slf4j-demo</module>
<module>provider</module>
- <module>logging-filter</module>
+ <module>logging-filter</module>
</modules>
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-release-plugin</artifactId>
- <version>2.4.2</version>
- <dependencies>
- <dependency>
- <groupId>org.apache.maven.scm</groupId>
- <artifactId>maven-scm-provider-gitexe</artifactId>
- <version>1.8.1</version>
- </dependency>
- </dependencies>
- </plugin>
- <!-- Checkstyle plugin - used to report on compliance with -->
- <!-- the Google style guide. -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-site-plugin</artifactId>
- <version>3.6</version>
- </plugin>
- <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
- <plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>
- org.apache.maven.plugins
- </groupId>
- <artifactId>
- maven-compiler-plugin
- </artifactId>
- <versionRange>
- [3.2,)
- </versionRange>
- <goals>
- <goal>compile</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore></ignore>
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
<properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
- <reporting>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.6.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.23.4</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
<plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <version>2.17</version>
- <reportSets>
- <reportSet>
- <reports>
- <report>checkstyle</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.7.0</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.4.2</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-gitexe</artifactId>
+ <version>1.8.1</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ <!-- Checkstyle plugin - used to report on compliance with -->
+ <!-- the Google style guide. -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>3.6</version>
+ </plugin>
</plugins>
-</reporting>
- <dependencies>
- <!-- pulls in banned logback-core 1.1.3 -->
- <!-- dependency>
- <groupId>com.att.eelf</groupId>
- <artifactId>eelf-core</artifactId>
- <version>1.0.0</version>
- </dependency-->
- <!-- JUnit 4.12 used to come with EELF -->
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <version>1.6.4</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.12</version>
- <scope>test</scope>
- </dependency>
+ </pluginManagement>
+ </build>
- </dependencies>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>2.17</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>checkstyle</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
diff --git a/reference/provider/pom.xml b/reference/provider/pom.xml
index b9f98b6..6a6e054 100644
--- a/reference/provider/pom.xml
+++ b/reference/provider/pom.xml
@@ -1,12 +1,15 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
<parent>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-reference</artifactId>
- <version>1.6.2-SNAPSHOT</version>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-reference</artifactId>
+ <version>1.6.10-SNAPSHOT</version>
</parent>
+
<artifactId>logging-provider</artifactId>
<packaging>pom</packaging>
- <name>logging-provider</name>
+
+ <name>logging-analytics :: ${project.artifactId}</name>
</project>
diff --git a/releases/1.6.3.yaml b/releases/1.6.3.yaml
new file mode 100644
index 0000000..de2a11a
--- /dev/null
+++ b/releases/1.6.3.yaml
@@ -0,0 +1,4 @@
+distribution_type: 'maven'
+version: '1.6.3'
+project: 'logging-analytics'
+log_dir: 'logging-analytics-maven-stage-master/295/'
diff --git a/releases/1.6.4.yaml b/releases/1.6.4.yaml
new file mode 100644
index 0000000..11bf54b
--- /dev/null
+++ b/releases/1.6.4.yaml
@@ -0,0 +1,5 @@
+---
+distribution_type: 'maven'
+version: '1.6.4'
+project: 'logging-analytics'
+log_dir: 'logging-analytics-maven-stage-master/302/'
diff --git a/releases/1.6.5.yaml b/releases/1.6.5.yaml
new file mode 100644
index 0000000..3e78da6
--- /dev/null
+++ b/releases/1.6.5.yaml
@@ -0,0 +1,5 @@
+---
+distribution_type: 'maven'
+version: '1.6.5'
+project: 'logging-analytics'
+log_dir: 'logging-analytics-maven-stage-master/317/'
diff --git a/releases/1.6.6.yaml b/releases/1.6.6.yaml
new file mode 100644
index 0000000..46b24fd
--- /dev/null
+++ b/releases/1.6.6.yaml
@@ -0,0 +1,5 @@
+---
+distribution_type: 'maven'
+version: '1.6.6'
+project: 'logging-analytics'
+log_dir: 'logging-analytics-maven-stage-master/339/' \ No newline at end of file
diff --git a/releases/1.6.7.yaml b/releases/1.6.7.yaml
new file mode 100644
index 0000000..d6e4bbf
--- /dev/null
+++ b/releases/1.6.7.yaml
@@ -0,0 +1,5 @@
+---
+distribution_type: 'maven'
+version: '1.6.7'
+project: 'logging-analytics'
+log_dir: 'logging-analytics-maven-stage-master/459/' \ No newline at end of file
diff --git a/releases/1.6.8.yaml b/releases/1.6.8.yaml
new file mode 100644
index 0000000..f23f23d
--- /dev/null
+++ b/releases/1.6.8.yaml
@@ -0,0 +1,5 @@
+---
+distribution_type: 'maven'
+version: '1.6.8'
+project: 'logging-analytics'
+log_dir: 'logging-analytics-maven-stage-master/521/' \ No newline at end of file
diff --git a/releases/1.6.9.yaml b/releases/1.6.9.yaml
new file mode 100644
index 0000000..208addd
--- /dev/null
+++ b/releases/1.6.9.yaml
@@ -0,0 +1,5 @@
+---
+distribution_type: 'maven'
+version: '1.6.9'
+project: 'logging-analytics'
+log_dir: 'logging-analytics-maven-stage-master/759/' \ No newline at end of file
diff --git a/version.properties b/version.properties
index 5ea81e0..e914c2a 100644
--- a/version.properties
+++ b/version.properties
@@ -19,7 +19,7 @@
# 1.2.6-SNAPSHOT is off 1.2.5
major=1
minor=6
-patch=1
+patch=10
base_version=${major}.${minor}.${patch}