aspose file tools*
The moose likes Other Open Source Projects and the fly likes FileAppender path -log4j Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "FileAppender path -log4j " Watch "FileAppender path -log4j " New topic
Author

FileAppender path -log4j

Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147
Hi all ,
I am using the log4j thorugh the properties file and I use the File Appender,everything works fine..but
Our production enviroment is UNIX and Development is Windows ,I am having problem specifying the File Appender path, it seems there is no way to specify a relative path?

What is the best solution to solve this problem?
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Not sure if you're running a web app but this topic, RE: FileAppender file path in a web app, in the log4j-user mailing list archive has some suggestions... some useful even it's not a web app.

If that doesn't help, please provide some details about what you've tried and what kind of result you're getting.
Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147
hi ,

Thanks for the reply.Yes It is in web application.I went to through the link you gave,i tried to do it using the system properties.I didn't exactly understand the other options.

This is how I did on a linx machine, but it didn't work.

log4j.logger.com.nbd.xmlgateway=info,R

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=${CATALINA_HOME}/logs/xmlgateway/xmlgatewaylog.log
log4j.appender.R.DatePattern='.'yyyy-MM-dd

Thanks
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
You could try catalina.base or catalina.home or set something of your own when you start your server like, -Dlog4j.log.dir=/my/logging/path

Looks like it needs to be a system property not just an environment variable. (looking in catalina.sh in tomcat 5.0.19 bin directory I see commands built including -Dcatalina.home="$CATALINA_HOME" )

In your properties file you can add log4j.debug=true so you can see what it is trying to do.
Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147
could you explain that little bit more clearly.

Thanks
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Which part?



Add log4j.debug=true to your properties file and you may get some useful output.

1. a scenario that works for me
Running a simple java class on the command line I can do this:

java -Dlog4j.log.dir=/my/logging/path MyClass

If in my log4j.properties file I have this it finds log4j.log.dir, see output in square bracket):

log4j.appender.ROLL.File=${log4j.log.dir}/minute.log

[debug output: log4j: Setting property [file] to [my/logging/path/minute.log].]

2. A scenario that doesn't work for me.

On the other hand if I run my class after setting it as an environment variable (using the syntax that works for the env I'm on today) it doesn't know about log4j.log.dir:

set log4j.log.dir=/my/logging/path
java MyClass

[debug output: log4j: Setting property [file] to [/minute.log].]

3. If you're using tomcat and CATALINA_HOME doesn't work, try catalina.base or catalina.home. This was suggested by an email I found searching in the archive I pointed you to. It looks like the CATALINA_HOME environment variable may used to set a system property catalina.home. I just peeked in one of the tomcat scripts but didn't verify that.

4. If that's not clear or you have questions please be more specific. I don't have time to write a dissertation, just trying to point you in a helpful direction.
[ May 05, 2005: Message edited by: Carol Enderlin ]
Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147
Thanks for the explanation.

Yes it works by editing the JAVA_OPTS variable in catalina.sh.It is recognizing the path.

But i have another problem, as another developer already have some value setup for that variable I am trying to figure out the syntax for adding multiple system properties.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
They should work with a space between them.

>set JAVA_OPTS= -Dlog4j.file.name=hmmm.log -Dlog4j.log.home=my/log/dir

>java %JAVA_OPTS% chapter4.Rolling 2 chapter4/periodic1b.properties

log4j: Setting property [file] to [my/log/dir/hmmm.log].

In some unix scripts we set a bunch of them and use quotes around the value, it happens to be named PROPERTIES in this script:

PROPERTIES="$PROPERTIES -Dx.y.x=mypropertyvaluehere"
PROPERTIES="$PROPERTIES -Danother.version=8.4.1"
[ May 05, 2005: Message edited by: Carol Enderlin ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileAppender path -log4j
 
Similar Threads
Server loggng with log4j Tomcat 6.x
remove log4j appender from an API
Struck thread and deadlock while getting connection
Log4J - File appender in 2 or more files for the same package.
log4J: could not able to see the log file