0

We are developing a Multi Tenant Application. I want to add the tenant name before each log message

.... [liquiforce] New User John Kid created

..... [moreiq] Fetched 4 Samples for Project 12

In the above example the

  1. "..." denotes the usual time stamp, process id, log level, class names e.g 2016-03-28 21:15:35.219 WARN 8 --- [ main] d.s.r.o.OperationImplicitParameterReader :
  2. [liquiforce] is my tenant name. The first log is from an action from liquiforce tenant and second from moreiq tenant
  3. I will be referring to the tenant information from the SecurityContext of Spring

This is all part of spring boot which uses default logback logging.

Cheers, Rohit

  • 1
    Did you thought about using MDC? – daniel.eichten Mar 29 '16 at 07:51
  • Using logback, you can configure the pattern of your logs in the logback.xml file. Some variables already contain level, date, method, etc. In your code, you can define your own variable if you need to. – Eria Mar 29 '16 at 09:12

1 Answers1

0

If you prefer to configure in logback-spring.xml, take a look at the answers in this question.
If you prefer to configure in Java code, take a look at the answers in this question.

Anyway, using logback-spring.xml is better, here is an example.

<springProperty name="prefix" source="spring.prefix"/>
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>${prefix} - %msg</file>
</appender>
6324
  • 4,678
  • 8
  • 34
  • 63