I want to create a custom log4j2 rolling file appender. I need to create this custom appender because I want to wrap the log4j log event with some information unique to my a
The application you are upgrading uses Apache Commons Logging, and there is no ThreadContext map in the Commons Logging API.
However, you can accomplish your object by simply using the log4j2 ThreadContext map in your application. That way you don't need any custom log events or appender subclasses.
There should only be a few places in your application where the userID is set or modified. In those places, add these lines of code:
int userId = //get user Id
String appplicationName = //get application name
ThreadContext.put("userID", String.valueOf(userId));
ThreadContext.put("appplicationName", appplicationName);
// ... your business logic
If Commons Logging is delegated to log4j2, you can configure a pattern layout like: "%-5p [%t] %c: %X{userID}/%{appplicationName} %m%n"
to make your values appear in the log.