The best way to demonstrate the mObg3n load time logging is by example.
For this example we need the following libraries from the package:
logger-loadtime-aspect-1.0.0.0-jar-with-dependencies.jar
aspectjweaver-1.6.12.jar (i.e. from the dependencies folder)
Also we need two mandatory configuration files below to be available in the Java classpath:
logger-aspect-context.xml (i.e. check the attachments.)
log4j.properties (i.e. if not yet available in the project we can check the attachments.)
If everything is ready we can now make our hands dirty.
1 Create a folder where all of the items need libraries and configuration files are placed.
2 Two java classes that don't have any logging information.
PersonBean class (i.e. included in the attached sample-classes.tar.gz.)
package org.sample.logger.bean;
public class PersonBean {
private String firstName;
private String middleName;
private String lastName;public String getFirstName() {
return firstName;
}public void setFirstName(String firstName) {
this.firstName = firstName;
}public String getMiddleName() {
return middleName;
}public void setMiddleName(String middleName) {
this.middleName = middleName;
}public String getLastName() {
return lastName;
}public void setLastName(String lastName) {
this.lastName = lastName;
}public String getFullName() {
return new StringBuilder(lastName.toUpperCase()).append(", ")
.append(firstName.toUpperCase()).append(" ")
.append(middleName.toUpperCase()).toString();
}public String toString() {
return getFullName();
}}
SampleApp class (i.e. included in the attached sample-classes.tar.gz.)
package org.sample.logger.app;
import org.sample.logger.bean.PersonBean;
public class SampleApp {
public static void main(String[] args) {
PersonBean person = new PersonBean();person.setFirstName("FirstName"); person.setLastName("LastName"); person.setMiddleName("MiddleName"); System.out.println("Person=" + person);}
}
3 Compile all the classes.
4 Run it with the command below:
java -javaagent:aspectjweaver-1.6.12.jar -cp .:logger-loadtime-aspect-1.0.0.0-jar-with-dependencies.jar org.sample.logger.app.SampleApp
The output must be something similar to this if we use the attached log4j.properties:
See also [Refining Target Methods]
Wiki: Including Logging Aspect at Compile Time
Wiki: MObG3n Logger Home
Wiki: Refining Target Methods