Search code examples
javalog4jtomcat7multi-tenant

Log exceptions in separate files for each tenant in multi-tenancy architecture


I having an application with multi-tenancy support, that is one server and multiple DB, there will be separate DB for each tenant. All the exceptions thrown in the application will be logged in one single log. The tenantID will be printed along with the exception.

I would like to handle it in separate file, i.e for each tenant a separate log file. This will be helpful in identifying that this exception is caused because of the activity done by a user belonging to a particular tenant. Is there any possibilities for achieving this using custom ObjectRenderer or any other techniques. Thanks in advance.


Solution

  • My suggestion is to create your own Appenders. In custom Appenders you can do any thing you want like separate log file etc..,

    Reference : How to create a own Appender in log4j? http://logging.apache.org/log4j/2.x/manual/extending.html