Skip to content

Instantly share code, notes, and snippets.

@jamesmorgan
Created August 4, 2011 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmorgan/1125076 to your computer and use it in GitHub Desktop.
Save jamesmorgan/1125076 to your computer and use it in GitHub Desktop.
Sample Logging Aspect
@Aspect
public class LoggingAspect {
private ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
@Before("execution(@com.morgan.design.demo.annotation.LogMe(com.morgan.design.demo.annotation.LoggingLevel.WARN) * *(..))")
public void loggerWarn(final JoinPoint jp) throws Throwable {
final Logger logger = getLoggerForClass(jp);
logger.warn(buildLogging(jp));
}
private Logger getLoggerForClass(final JoinPoint jp) {
return this.iLoggerFactory.getLogger(jp.getSignature()
.getDeclaringType()
.getName());
}
private String buildLogging(final JoinPoint jp) {
final StringBuilder message = new StringBuilder();
message.append("Method Invocation=[")
.append(jp.getSignature()
.getName())
.append("]")
.append(" - Args=")
.append(Arrays.toString(jp.getArgs()));
return message.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment