Link to home
Create AccountLog in
Avatar of ank5
ank5Flag for India

asked on

Specify log location using Log4j

I have a war file which uses log4j for logging.
Log4j.properties has the following for log file creation -

log4j.appender.fileAppender.File=C:/temp/MyApplication.log

The problem is that this war file is going to be deployed in Windows and Linux, so I don't want to hard code it to c:/temp.

Is there a way to provide this path in a generic way, say using some environment variables, java home, user directory etc.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Try

log4j.appender.fileAppender.File=${user.home}/MyApplication.log

Open in new window

Such config details should not be part of war file . Instead it should be in an external properties file , which would be read by one of your classes packaged into the war
SOLUTION
Avatar of Valeri
Valeri
Flag of Bulgaria image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of ank5

ASKER

>>on which server you are running this appl?

It's tcserver
How is that relevant btw?
Avatar of ank5

ASKER

log4j.appender.fileAppender.File=${user.home}/MyApplication.log

I tried this but it does not seem to work. Attached is how the log file looks like, is there something wrong in it?


Thanks
log4j.txt
Avatar of ank5

ASKER

>>Such config details should not be part of war file . Instead it should be in an external properties file , which would be read by one of your classes packaged into the war

This isn't really an option for me. This log4j.properties is provided as a part of the product (Documentum xCP in this case), I can only modify it add logging for my custom classes.
if you want a different path for windows and linux then you have to have something like configuration file that is different for windows and linux.
after reading this file at the beginning /before to initialize Log4J/ you can set the path properly in this way:

System.setProperty("logPath", "the path specified in the config file");

then in your Log4J.properties file you have to have this:
log4j.appender.fileAppender.File=${logPath}/yourLogFile.out
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of ank5

ASKER

Hi CEHJ

Can you please try it with the log file that I had posted. I think that my log file may be incorrect.

Thank you
That's what i did try it with (hence the same package name as yours) ;)
Avatar of ank5

ASKER

There was a problem with the product, it was loading the wrong log4j.properties file, hence closing the question.

Thanks for your inputs.
Avatar of ank5

ASKER

The new package name structure is

com.lowagie.text.pdf.PdfWriter;

It seems that they have completely refactored their API.
Avatar of ank5

ASKER

-
Avatar of ank5

ASKER

Please ignore the last two comments, they were posted in this question by mistake. I can't find an option to delete these comments.
Never mind :)