By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

Logger Object

P: 3
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.writeLog("Changed count from" + count + " to " +
i);
count = i;
}

public int getCount() {
return count;
}
}

This code I modified from the book.
Jan 2 '07 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
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.writeLog("Changed count from" + count + " to " +
i);
count = i;
}

public int getCount() {
return count;
}
}

This code I modified from the book.
Yeah the design could be argued a lot. I'd personaly prefer a logger that has static methods and so I'd not have to include the logger object in my design.
Jan 3 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.