package lawOfDemeter; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; /** * This aspect monitors all of the print statements in the LoDChecker application, * capturing them and sending them to a log file. */ privileged aspect Logging { // create the logger static Logger log = Logger.getLogger(Logging.class.getName()); boolean isInitialized = false; private pointcut printStatement(String s): within(lawOfDemeter..*) && call(* *.print*(String)) && args(s); before(): execution(void *.main(String[])){ // load the configuration from the configuration file if(!isInitialized){ PropertyConfigurator.configure("LoDLogger.lcf"); isInitialized = true; log.error("******"); log.error("****** Starting new session ["+(new java.util.Date())+"] *******"); log.error("******\n"); } } void around(String s): printStatement(s){ log.warn(s); } }