views:

437

answers:

2

I am instantiating a log4j object inside of a class which inherits most of the methods and attributes from a parent class. Right now I'm getting logging messages from the subclass only. How can I get logging messages to output in both the super class and subclass?

EDIT: The way I am do the logging is that I have an instance variable in both the subclass and superclass, so it would look something like the following:

public class SuperClass {
/**
 * Logger for this class
 */
private static final Logger logger = Logger.getLogger(SuperClass.class); 

/* Rest of code goes here */
} // end SuperClass

And the same for the subclass.

My log4j configuration:

## gps log4j.rootLogger==ERROR, clientLog, catissuecoreclientLog

log4j.rootLogger==DEBUG, clientLog, catissuecoreclientLog
### direct messages to file hibernate.log ###

log4j.appender.clientLog=org.apache.log4j.FileAppender
log4j.appender.clientLog.File=./log/client.log
log4j.appender.clientLog.layout=org.apache.log4j.PatternLayout
log4j.appender.clientLog.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

log4j.appender.catissuecoreclientLog=org.apache.log4j.FileAppender
log4j.appender.catissuecoreclientLog.File=./log/catissuecoreclient.log
log4j.appender.catissuecoreclientLog.layout=org.apache.log4j.PatternLayout
log4j.appender.catissuecoreclientLog.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1} - %m%n

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

#log4j.rootLogger=warn, stdout
#log4j.rootLogger=warn, file
#log4j.logger.org.hibernate=info

### log just the SQL
#log4j.logger.org.hibernate.SQL=debug

### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info

### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug

### log cache activity ###
#log4j.logger.org.hibernate.cache=debug

### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
+1  A: 

You would need to make the logger visible in super class as well.

Normally the setup is to create a logger static variable in each class to allow each class to have different logging level. e.g.

private static final Logger LOG = Logger.getLogger( ClassName.class.getName() );

Where you enter your class's name instead of ClassName

Mark
+1  A: 

Umm... by actually logging them?

You need to invoke log4j's logging methods (debug(), info(), error(), etc...) from whatever method of whatever class you want to log message from. You can then configure (in your log4j.properties) what messages are visible / logged / go to what log file / etc... per class level (if you so choose).

ChssPly76
Was about to type this... +1
Aviator
I do know how to invoke the logging methods - that's not the issue. The issue is that I am not getting any of the logging statements from the superclass. I have configured the level of logging to be DEBUG.
Brian Lewis
Can you post your log4j configuration? Is logging for both `SuperClass` and subclass set to DEBUG level?
ChssPly76
I posted the contents of my config file in the original question. And, yes, I also set the level of the logger instance variables in both the subclass and superclass to DEBUG.
Brian Lewis