- 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
<type>pom</type>
<scope>import</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-starter-sleuth</artifactId>
+ <version>3.1.1</version>
+ </dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-bom</artifactId>
<type>pom</type>
<scope>import</scope>
</dependency>
+ <dependency>
+ <groupId>net.logstash.logback</groupId>
+ <artifactId>logstash-logback-encoder</artifactId>
+ <version>7.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.janino</groupId>
+ <artifactId>janino</artifactId>
+ <version>3.1.7</version>
+ </dependency>
+ <dependency>
+ <groupId>com.vladmihalcea</groupId>
+ <artifactId>hibernate-types-52</artifactId>
+ <version>2.10.0</version>
+ </dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
- <version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<version>0.18.0</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-starter-sleuth</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.logstash.logback</groupId>
+ <artifactId>logstash-logback-encoder</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.janino</groupId>
+ <artifactId>janino</artifactId>
+ </dependency>
</dependencies>
<build>
base-path: /cps-temporal/api
spring:
+ application:
+ name: cps-temporal
datasource:
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/cpstemporaldb
username: ${DB_USERNAME}
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
--- /dev/null
+<!--
+ ============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>
+++ /dev/null
-<!--
- ============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>
base-path: /cps-temporal/api
spring:
+ application:
+ name: cps-temporal
datasource:
url: ${DB_URL}
username: ${DB_USERNAME}
auth:
username: testUser
password: testPassword
+
+logging:
+ format: json