Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Paul Clapham wrote:Use an instance variable instead of a static variable. Then your boilerplate looks like this:
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Bear Bibeault wrote:I believe this is the sort of "cross-cutting concern" that AOP (Aspect-Oriented Programming) is meant to deal with.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Paul Clapham wrote:I'm sure it's far too late for me to say this, but it isn't a requirement of log4j that you use the class name for the name of the logger. That's only useful if you're going to configure log4j so that logs from different classes are written to different appenders -- maybe you are doing that, or maybe not. People just tend to use the class name there because the log4j documentation did that (to demonstrate how multiple loggers work and so on) but it isn't necessary.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Paul Anilprem wrote:May be I am missing something in the log4j API, but can you tell me how can you append the source of the message (i.e. the class name) if you don't create the logger with the name?
Paul Clapham wrote:
Paul Anilprem wrote:May be I am missing something in the log4j API, but can you tell me how can you append the source of the message (i.e. the class name) if you don't create the logger with the name?
Well, do you want to output the class name or the logger name? As I said, they don't have to be the same. The documentation of PatternLayout (here) just says that you can use %C to get the name of the class which issued the logging request. It doesn't say anything about the logger name having to be the same as the class name.
I've always used specific logger names in my code for the appenders to key off of.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Paul Clapham wrote:No, people use the class name as the logger name because they haven't ever seen any other method of assigning logger names. That's my opinion anyway. And your other comment is just premature optimization. That's not only my opinion but that of a lot of other people.
WARNING Generating the caller class information is slow. Thus, use should be avoided unless execution speed is not an issue.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Paul Anilprem wrote:Description of %C from the link you mentioned:
WARNING Generating the caller class information is slow. Thus, use should be avoided unless execution speed is not an issue.