[CPS] Security logging fields 73/131073/6
authormpriyank <priyank.maheshwari@est.tech>
Thu, 22 Sep 2022 09:41:54 +0000 (10:41 +0100)
committerFiachra Corcoran <fiachra.corcoran@est.tech>
Thu, 3 Nov 2022 14:28:09 +0000 (14:28 +0000)
- Removed the old logback.xml file.
- Added logback-spring.xml with the new format for logging in json
  format
- Updated the file mount path in deployment file.
- Above change is just for CPS-Core

Issue-ID: CPS-1291
Change-Id: If1b657a4959023fc18d0a4710891a55dfeb29b22
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
kubernetes/cps/components/cps-core/resources/config/logback-spring.xml [new file with mode: 0644]
kubernetes/cps/components/cps-core/resources/config/logback.xml [deleted file]
kubernetes/cps/components/cps-core/templates/deployment.yaml

diff --git a/kubernetes/cps/components/cps-core/resources/config/logback-spring.xml b/kubernetes/cps/components/cps-core/resources/config/logback-spring.xml
new file mode 100644 (file)
index 0000000..0307602
--- /dev/null
@@ -0,0 +1,75 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2021-2022 Nordix Foundation
+ ================================================================================
+ 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.
+
+ SPDX-License-Identifier: Apache-2.0
+ ============LICENSE_END=========================================================
+-->
+
+<configuration scan="true" scanPeriod="30 seconds" debug="false">
+
+    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
+    <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
+
+    <springProperty scope="context" name="springAppName" source="spring.application.name"/>
+    <springProperty scope="context" name="username" source="security.auth.username"/>
+    <springProperty scope="context" name="loggingFormat" source="logging.format"/>
+
+    <property name="currentTimeStamp" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC}"/>
+
+    <appender name="jsonConsole"
+              class="ch.qos.logback.core.ConsoleAppender">
+        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
+            <providers>
+                <pattern>
+                    <omitEmptyFields>true</omitEmptyFields>
+                    <pattern>
+                        {
+                        "logTimeStamp": "${currentTimeStamp:-}",
+                        "logTypeName": "",
+                        "logLevel": "%level",
+                        "traceId": "%X{traceId:-}",
+                        "statusCode": "",
+                        "principalId": "${username:-}",
+                        "serviceName": "${springAppName:-}",
+                        "message": "%message",
+                        "spanId": "%X{spanId:-}",
+                        "processId": "${PID:-}",
+                        "threadName": "%thread",
+                        "class": "%logger{40}",
+                        "exception": "%wEx"
+                        }
+                    </pattern>
+                </pattern>
+            </providers>
+        </encoder>
+    </appender>
+
+    <appender name="asyncConsole" class="ch.qos.logback.classic.AsyncAppender">
+        <if condition='property("loggingFormat").equalsIgnoreCase("json")'>
+            <then>
+                <appender-ref ref="jsonConsole"/>
+            </then>
+            <else>
+                <appender-ref ref="CONSOLE"/>
+            </else>
+        </if>
+    </appender>
+
+    <root level="INFO">
+        <appender-ref ref="asyncConsole"/>
+    </root>
+
+</configuration>
diff --git a/kubernetes/cps/components/cps-core/resources/config/logback.xml b/kubernetes/cps/components/cps-core/resources/config/logback.xml
deleted file mode 100644 (file)
index 8256cfa..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<!--
-  ============LICENSE_START=======================================================
-   Copyright (C) 2020 Bell Canada.
-  ================================================================================
-  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.
-  SPDX-License-Identifier: Apache-2.0
-  ============LICENSE_END=========================================================
--->
-
-<configuration scan="true" scanPeriod="30 seconds" debug="false">
-
-    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
-        <encoder>
-            <pattern>%d - %highlight(%-5level) [%-20.20thread] %cyan(%logger{36}) - %msg%n</pattern>
-        </encoder>
-    </appender>
-    <appender name="AsyncSysOut" class="ch.qos.logback.classic.AsyncAppender">
-        <appender-ref ref="STDOUT" />
-    </appender>
-
-    <root level="INFO">
-        <appender-ref ref="AsyncSysOut" />
-    </root>
-
-</configuration>
-
index 1b482f4..3684aab 100644 (file)
@@ -126,8 +126,8 @@ spec:
           - mountPath: /app/resources/application-helm.yml
             subPath: application-helm.yml
             name: init-data
-          - mountPath: /app/resources/logback.xml
-            subPath: logback.xml
+          - mountPath: /app/resources/logback-spring.xml
+            subPath: logback-spring.xml
             name: init-data
           - mountPath: /tmp
             name: init-temp