diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/logging/TenantIdentifierLoggingConverter.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/logging/TenantIdentifierLoggingConverter.java
new file mode 100644
index 000000000..dde208c33
--- /dev/null
+++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/logging/TenantIdentifierLoggingConverter.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.fineract.infrastructure.core.logging;
+
+import ch.qos.logback.classic.pattern.ClassicConverter;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
+
+public class TenantIdentifierLoggingConverter extends ClassicConverter {
+
+ @Override
+ public String convert(ILoggingEvent event) {
+ return ThreadLocalContextUtil.getTenant() != null ? ThreadLocalContextUtil.getTenant().getTenantIdentifier() : "no-tenant";
+ }
+}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/migration/TenantDatabaseUpgradeService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/migration/TenantDatabaseUpgradeService.java
index e44523aa4..9f4e81033 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/migration/TenantDatabaseUpgradeService.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/migration/TenantDatabaseUpgradeService.java
@@ -39,6 +39,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.boot.FineractProfiles;
import org.apache.fineract.infrastructure.core.config.FineractProperties;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.apache.fineract.infrastructure.core.service.tenant.TenantDetailsService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -186,22 +187,28 @@ public class TenantDatabaseUpgradeService implements InitializingBean {
* @throws LiquibaseException
*/
private void upgradeIndividualTenant(FineractPlatformTenant tenant) throws LiquibaseException {
- log.info("Upgrade for tenant {} has started", tenant.getTenantIdentifier());
- try (HikariDataSource tenantDataSource = tenantDataSourceFactory.create(tenant)) {
- // 'initial_switch' and 'custom_changelog' contexts should be controlled by the application configuration
- // settings, and we should not use them to control the script order
- if (databaseStateVerifier.isFirstLiquibaseMigration(tenantDataSource)) {
- ExtendedSpringLiquibase liquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, CUSTOM_CHANGELOG_CONTEXT,
- INITIAL_SWITCH_CONTEXT, tenant.getTenantIdentifier());
- applyInitialLiquibase(tenantDataSource, liquibase, tenant.getTenantIdentifier(),
- (ds) -> !databaseStateVerifier.isTenantOnLatestUpgradableVersion(ds));
+ try {
+ ThreadLocalContextUtil.setTenant(tenant);
+ log.info("Upgrade for tenant {} has started", tenant.getTenantIdentifier());
+ try (HikariDataSource tenantDataSource = tenantDataSourceFactory.create(tenant)) {
+ // 'initial_switch' and 'custom_changelog' contexts should be controlled by the application
+ // configuration
+ // settings, and we should not use them to control the script order
+ if (databaseStateVerifier.isFirstLiquibaseMigration(tenantDataSource)) {
+ ExtendedSpringLiquibase liquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT,
+ CUSTOM_CHANGELOG_CONTEXT, INITIAL_SWITCH_CONTEXT, tenant.getTenantIdentifier());
+ applyInitialLiquibase(tenantDataSource, liquibase, tenant.getTenantIdentifier(),
+ (ds) -> !databaseStateVerifier.isTenantOnLatestUpgradableVersion(ds));
+ }
+ SpringLiquibase tenantLiquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, CUSTOM_CHANGELOG_CONTEXT,
+ tenant.getTenantIdentifier());
+ tenantLiquibase.afterPropertiesSet();
+ log.info("Upgrade for tenant {} has finished", tenant.getTenantIdentifier());
+ } catch (Exception e) {
+ throw new RuntimeException("Exception while upgrading tenant " + tenant.getTenantIdentifier(), e);
}
- SpringLiquibase tenantLiquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, CUSTOM_CHANGELOG_CONTEXT,
- tenant.getTenantIdentifier());
- tenantLiquibase.afterPropertiesSet();
- log.info("Upgrade for tenant {} has finished", tenant.getTenantIdentifier());
- } catch (Exception e) {
- throw new RuntimeException("Exception while upgrading tenant " + tenant.getTenantIdentifier(), e);
+ } finally {
+ ThreadLocalContextUtil.reset();
}
}
diff --git a/fineract-provider/src/main/resources/application.properties b/fineract-provider/src/main/resources/application.properties
index 286a5a2bc..93934d9ab 100644
--- a/fineract-provider/src/main/resources/application.properties
+++ b/fineract-provider/src/main/resources/application.properties
@@ -284,7 +284,7 @@ fineract.sql-validation.profiles[2].patternRefs[6].order=6
fineract.sql-validation.profiles[2].enabled=true
# Logging pattern for the console
-logging.pattern.console=${CONSOLE_LOG_PATTERN:%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(%replace([%X{correlationId}]){'\\[\\]', ''}) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}}
+logging.pattern.console=${CONSOLE_LOG_PATTERN:%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(%replace([%X{correlationId}]){'\\[\\]', ''}) [%15.15tenantId] %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}}
logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]
management.health.jms.enabled=${FINERACT_MANAGEMENT_HEALTH_JMS_ENABLED:false}
diff --git a/fineract-provider/src/main/resources/logback-spring.xml b/fineract-provider/src/main/resources/logback-spring.xml
index 2b2c2a301..84fe601f2 100644
--- a/fineract-provider/src/main/resources/logback-spring.xml
+++ b/fineract-provider/src/main/resources/logback-spring.xml
@@ -26,6 +26,9 @@
and https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback -->
+
+
${CONSOLE_LOG_PATTERN}