Does someone know how to add a custom to logger MDC [message #1841080] |
Mon, 03 May 2021 06:36  |
Eclipse User |
|
|
|
Here the step i have followed
1. Create a classe in app.server
@ApplicationScoped
public class MainGroupContextValueProvider implements IDiagnosticContextValueProvider {
public static final String KEY = "group.name";
@Override
public String key() {
return KEY;
}
@Override
public String value() {
final ISession session = ISession.CURRENT.get();
return session != null ? ((ServerSession)session).getUserMainGroup() : "DefaultUserGroup";
}
}
getUserMainGroup is loaded from database in `execLoadSession` and setted into setSharedContextVariable to be accessible on Client side
2. Create a custom RunContext
@Replace
public class CustomServerRunContext extends ServerRunContext {
@Override
protected <RESULT> void interceptCallableChain(final CallableChain<RESULT> callableChain) {
callableChain.add(new DiagnosticContextValueProcessor(BEANS.get(MainGroupContextValueProvider.class)));
super.interceptCallableChain(callableChain);
}
}
3. Add the custom value on config.properties.
<variable scope="context" name="mdcPattern" value="principal=%X{subject.principal.name}, group=%X{group.name}, scoutSession=%X{scout.session.id}, jobName=%X{scout.job.name}, cid=%X{scout.correlation.id}" />
When starting the application everything is correct, I have the default value of group "DefaultUserGroup" in the log. But I would expect to have another value when a user session is logged into the app. What did I forget? Is this the best way to go?
Thank you in advance.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07533 seconds