Currently I'm using logback MDC to set different tenants. But I wish to have different log levels for different tenants.
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<appender name="TENANT-THREAD" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator>
<key>tenantName</key>
<defaultValue>MYAPP</defaultValue>
</discriminator>
<sift>
<appender name="FILE-${tenantName}"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/${tenantName}.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} %mdc [%thread] %level %logger{35} - %msg%n
</Pattern>
</encoder>
</appender>
</sift>
</appender>
<root level="DEBUG">
<appender-ref ref="TENANT-THREAD"/>
</root>
</configuration>
MDC.put("tenantName", tenantName);
MDC.remove("tenantName");
Is it possible to set different log level for different tenants programmatically?
To change log level programmatically use:
Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.INFO);
Level.INFO
being the selected level
The following steps can be done by wrapping the logger through a custom TenantLogger
This would need a separate table like TenantLoggingConfig
which would contain columns like TenantId
, ModuleId
, LogLevel
etc.
You can have modules like customer, orders, products etc. In case of microservices, this is simple in the sense that each microservice contains only its modules.
kindly share your thoughts on this or if you prefer any alternative approach.
You can use following steps to achieve the same
Hope you find this helpful
vp
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.