Hi,
This is my first post, and I got questions about logging.
When something happen within an object, and if I would like to log the event, what would be a good way to do it?
1. I make the logger object embedded in the class and use it (as the one below)
2. I have only one logger that other objects can call. Create Logger once, and let it stay there where other objects can call for services.
The reason I asked this question about this because I've been reading some concept about AOP, which mentioned an example on the logging extensively. The question above is not related to the AOP(haven't got that far yet). I've just wondered why people embedded the logger in the class.
What would be good practices to create logger objects?
What would be an effect if I inherit the based class that contains the logger object?
public class P {
private int count;
Logger loggerObject;
P( ) {
count = 0;
loggerObject = new Logger();
}
public void putCount(int i) {
loggerObject.wr iteLog("Changed count from" + count + " to " +
i);
count = i;
}
public int getCount() {
return count;
}
}
This code I modified from the book.
This is my first post, and I got questions about logging.
When something happen within an object, and if I would like to log the event, what would be a good way to do it?
1. I make the logger object embedded in the class and use it (as the one below)
2. I have only one logger that other objects can call. Create Logger once, and let it stay there where other objects can call for services.
The reason I asked this question about this because I've been reading some concept about AOP, which mentioned an example on the logging extensively. The question above is not related to the AOP(haven't got that far yet). I've just wondered why people embedded the logger in the class.
What would be good practices to create logger objects?
What would be an effect if I inherit the based class that contains the logger object?
public class P {
private int count;
Logger loggerObject;
P( ) {
count = 0;
loggerObject = new Logger();
}
public void putCount(int i) {
loggerObject.wr iteLog("Changed count from" + count + " to " +
i);
count = i;
}
public int getCount() {
return count;
}
}
This code I modified from the book.
Comment