diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/main/resources/application.yml | 8 | ||||
-rw-r--r-- | src/main/resources/logback-spring.xml | 74 | ||||
-rw-r--r-- | src/main/resources/logback.xml | 43 | ||||
-rw-r--r-- | src/test/resources/application.yml | 5 |
4 files changed, 86 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> diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 9bdacbe..ce0e95b 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -24,6 +24,8 @@ rest: base-path: /cps-temporal/api spring: + application: + name: cps-temporal datasource: url: ${DB_URL} username: ${DB_USERNAME} @@ -71,3 +73,6 @@ security: auth: username: testUser password: testPassword + +logging: + format: json |