PL-6083 Add application name to logs

#PL-6083
This commit is contained in:
Eugeny Degtyarjov 2015-10-01 13:00:18 +00:00
parent 3d581cfac9
commit e365670bbc
3 changed files with 13 additions and 1 deletions

View File

@ -18,7 +18,8 @@ import org.springframework.context.ApplicationContext;
*/
public class LogMdc {
public static final String USER = "user";
public static final String USER = "cubaUser";
public static final String APPLICATION = "cubaApp";
public static void setup(SecurityContext securityContext) {
String userProp = AppContext.getProperty("cuba.logUserName");
@ -47,5 +48,14 @@ public class LogMdc {
MDC.remove(USER);
}
}
String applicationProp = AppContext.getProperty("cuba.logAppName");
if (applicationProp == null || Boolean.valueOf(applicationProp)) {
if (securityContext != null) {
MDC.put(APPLICATION, "/" + AppContext.getProperty("cuba.webContextName"));
} else {
MDC.remove(APPLICATION);
}
}
}
}

View File

@ -121,6 +121,7 @@ public class LocalServiceProxy extends RemoteAccessor implements FactoryBean<Obj
method.getName(), parameterTypeNames, argumentsData, notSerializableArguments, sessionId);
LocalServiceInvocationResult result = invoker.invoke(invocation);
AppContext.setSecurityContext(AppContext.getSecurityContext());//need reset application name in LogMDC for the current thread
// don't use SerializationUtils.deserialize() here to avoid ClassNotFoundException
if (result.getException() != null) {

View File

@ -121,6 +121,7 @@ public class LocalServiceProxy extends RemoteAccessor implements FactoryBean<Obj
method.getName(), parameterTypeNames, argumentsData, notSerializableArguments, sessionId);
LocalServiceInvocationResult result = invoker.invoke(invocation);
AppContext.setSecurityContext(AppContext.getSecurityContext());//need reset application name in LogMDC for the current thread
// don't use SerializationUtils.deserialize() here to avoid ClassNotFoundException
if (result.getException() != null) {