custom channel logging

Hello

wasn't sure if this is the right forum for this...

Has any one had any experience getting log4j/apache commons logging working when building custom channels?

I can get System.out.println outputting in $CP_ROOT/products/ws/https-cp/logs/errors but have not had any luck getting classes in my .car files in $CP_ROOT/webapps/luminis/WEB-INF/cars to log using log4j/apache commons logging.

ideally it would be fab to log each .car to its own log file..

cheers

nomit

0
No votes yet

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

*Example debug

*Example debug code*


package uk.ac.nottingham.compass.channels.wizzy;

...
import org.apache.log4j.Logger;
...
...

public class CSuperWizzyChannel extends NottinghamBaseChannel {

    	private static Logger _logger = Logger.getLogger( 
    		CSuperWizzyChannel.class.getName() 
    	);
	...
	...
	...
	public void exampleMethod(){
	
           // Note: Add the method name to the start of each message
           _logger.warn( "exampleMethod(): This is a warn message"); 
           _logger.error("exampleMethod(): This is a error message");
           _logger.info( "exampleMethod(): This is a info message");
           _logger.debug("exampleMethod(): This is a debug message");

	}
	...
	...
	...
}

When you need to debug a particular class/package...

Backup, then edit $CP_ROOT/webapps/luminis/WEB-INF/config/cplog4j.properties

Add the lines...

# cczdas - Debug for Super Wizzy Channel
log4j.category.uk.ac.nottingham.compass.channels.wizzy.CSuperWizzyChannel=DEBUG, file

then
tail -f $CP_ROOT/logs/cp.log

When you're done, remove/comment out the class/package in $CP_ROOT/webapps/luminis/WEB-INF/config/cplog4j.properties

*If you want to be extra fancy*, you could add your own log file for this particular channel...

So instead add (something like)...


## cczdas: Extra logging for wizzy channel ############################
log4j.category.uk.ac.nottingham.compass.channels.wizzy.CSuperWizzyChannel=DEBUG, wizzy
log4j.additivity.wizzy=false
## NB additivity=false so only doing this logging in wizzy.log BUT errors also appear in ROOT cp.log

log4j.appender.wizzy=org.apache.log4j.RollingFileAppender
log4j.appender.wizzy.File=${util.logservice.log4j.directory}/wizzy.log
log4j.appender.wizzy.MaxFileSize=1MB
log4j.appender.wizzy.MaxBackupIndex=5
log4j.appender.wizzy.layout=org.apache.log4j.PatternLayout
log4j.appender.wizzy.layout.ConversionPattern=%d{ISO8601} %x %m%n
#######################################################################

to $CP_ROOT/webapps/luminis/WEB-INF/config/cplog4j.properties

thanks uon_david!

Cheers for this - will give it a spin.
I was wondering if you have managed to seperate these configurations?
ie keep a seperate properties file for your own apps? to save customisation after upgrades etc.

I googled to see if there was any mention of a "includes" way of adding
log4j configs but couldn't see anything

cheeeeers

No.

We've not done what you suggested with "log4j includes".
Dunno whether it's possible either.

D.

having issues

I've tried this and nothing ever gets written to the log file, although the file was created. Does this only work with actual channel classes (classes that extend the base channel class) or can you log for any other class included in a car file? like i've got an smtp class and i only really need to log from it, so i've set up it for that class only, but it doesn't work for some reason...