Is there anyway to automatically add faces messages when logging?
if (event.getDate().compareTo(startDate) < 0) {
logger.warn(message.getValue("dateWarnMsg"));
FacesUtils.addWarnMessage(message.getValue("dateWarnMsg"));
}
I have a lot of code like this. Is there a way after a log to automatically add a faces message?
Something like this?
if (event.getDate().compareTo(startDate) &开发者_开发知识库lt; 0) {
logger.warn(message.getValue("dateWarnMsg"), addFacesMessage);
}
Thanks.
How about adding another method to FacesUtils
? Or wrapping it inside another class if FacesUtils
isn't part of your classes. Something like:
addWarnMessageAndLog(String warningMessage) {
logger.warn(warningMessage);
FacesUtils.addWarnMessage(warningMessage);
}
Using interceptors or some other form of aspect oriented programming might also help you if you don't like this route.
You can use Interceptors for that. Read more here.
精彩评论