public class CommandLogInterceptor implements MethodInterceptor {
private static final Logger log = LoggerFactory.getLogger(CommandLogInterceptor.class);
private void logResult(LogRecorder clr, String indent, String cmdStr, Result result, Context context) {
PageInformation prevInfo = context.getLatestPageInformation();
PageInformation info = new PageInformation(context);
CookieFilter cookieFilter = context.getCookieFilter();
String prefix = indent + "- Cookie: ";
if (result.isFailed()) {
String resStr = info.getFirstMessage(prevInfo, indent, cmdStr, "=>", result.toString());
log.error(resStr);
clr.error(resStr);
for (String message : info.cookieMap.allMessages(cookieFilter)) {
log.error(prefix + message);
clr.error(prefix + message);
}
} else {
String resStr = info.getFirstMessage(prevInfo, indent, "-", result.toString());
log.info(resStr);
clr.info(resStr);
List<String> messages;
if (info.isSameOrigin(prevInfo))
messages = info.cookieMap.diffMessages(cookieFilter, prevInfo.cookieMap);
else
messages = info.cookieMap.allMessages(cookieFilter);
for (String message : messages) {
log.info(prefix + message);