summaryrefslogtreecommitdiffstats
path: root/src/main/resources
diff options
context:
space:
mode:
authorsourabh_sourabh <sourabh.sourabh@est.tech>2022-05-04 11:53:01 +0100
committersourabh_sourabh <sourabh.sourabh@est.tech>2022-05-06 13:43:46 +0100
commita7863efca29d19ea07b3cdbad23e2b4335694c97 (patch)
treeef80f4eaf7b66fd75ad3942884ed7a8043c97f53 /src/main/resources
parentab3c7378c0cf96021856171d80b14b5a839f192e (diff)
Security Logging Fields
- logback encoder and sleuth dependencies are added. - New appender is added to log JSON format content on console. Issue-ID: CPS-986 Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech> Change-Id: I9e45a9d842831a87af3fb9ac309485110357f0c8
Diffstat (limited to 'src/main/resources')
-rwxr-xr-xsrc/main/resources/application.yml8
-rw-r--r--src/main/resources/logback-spring.xml74
-rw-r--r--src/main/resources/logback.xml43
3 files changed, 81 insertions, 44 deletions
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 7db9510..9b3be03 100755
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -25,6 +25,8 @@ rest:
base-path: /cps-temporal/api
spring:
+ application:
+ name: cps-temporal
datasource:
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/cpstemporaldb
username: ${DB_USERNAME}
@@ -90,4 +92,8 @@ management:
show-details: always
# kubernetes probes: liveness and readiness
probes:
- enabled: true \ No newline at end of file
+ enabled: true
+
+logging:
+ format: json
+ \ No newline at end of file
diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..c71c9a6
--- /dev/null
+++ b/src/main/resources/logback-spring.xml
@@ -0,0 +1,74 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (c) 2021 Bell Canada.
+ Modifications Copyright (C) 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.
+ ============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/src/main/resources/logback.xml b/src/main/resources/logback.xml
deleted file mode 100644
index a75b7aa..0000000
--- a/src/main/resources/logback.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (c) 2021 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.
- ============LICENSE_END=========================================================
--->
-
-<configuration>
-
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <encoder>
- <pattern>%d - %highlight(%-5level) [%-20.20thread] %cyan(%logger{36}) - %msg%n</pattern>
- </encoder>
- </appender>
-
- <!-- Logger for cps classes -->
- <logger name="org.onap.cps" level="info"/>
-
- <!-- Logger for sql statements. Set to info to disable, debug to enable -->
- <logger name="org.hibernate.SQL" level="info"/>
-
- <!-- Logger for sql bindings. Set to info to disable, to trace to enable -->
- <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="info"/>
-
- <!-- Logger for hibernate statistics. Set to warn to disable, to info to enable -->
- <logger name="org.hibernate.engine.internal.StatisticalLoggingSessionEventListener" level="warn"/>
-
- <root level="info">
- <appender-ref ref="STDOUT" />
- </root>
-
-</configuration>