aspose file tools*
The moose likes JBoss/WildFly and the fly likes How to have my own log4j.xml file in Jboss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "How to have my own log4j.xml file in Jboss" Watch "How to have my own log4j.xml file in Jboss" New topic
Author

How to have my own log4j.xml file in Jboss

avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
Hey,

I work with Jboss 4.2.
My application deploy as an ear file.

where should i put my log4j file in the application ear withot having a conflicts with Jboss?

thank you
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by avihai marchiano:

I work with Jboss 4.2.
My application deploy as an ear file.

where should i put my log4j file in the application ear withot having a conflicts with Jboss?


This is what I think should work , but there might be other better ways of doing the same.

you can have a config directory packed within the EAR and add an entry named Class-Path in the menifest.mf that you are planning to ship with this EAR and that should include this config directory.Now while packing this EAR put the log4j.xml in that config folder.
[ September 18, 2007: Message edited by: Rahul Bhattacharjee ]

Rahul Bhattacharjee
LinkedIn - Blog
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
jboss-4.2.1.GA\server\default\conf


SCJP, SCJD, SCWCD, SCBCD
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Darya Akbari:
jboss-4.2.1.GA\server\default\conf

I am not aware of the JBosses clasloading structure but it seems to me that putting the config file there would make it available to all the applications deployed in the server , not to one particular ear.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
I don't see why to put log4j.xml or jboss-log4j.xml (latest JBoss versions) into an EAR.

You normally leave it there where JBoss already put it for you. Here is where you control the output of JBoss' server.log file.

Regards,
Darya
[ September 22, 2007: Message edited by: Darya Akbari ]
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Darya Akbari:
I don't see why to put log4j.xml or jboss-log4j.xml (latest JBoss versions) into an EAR.


Because its specific to that application , not to all the applications hosted in that application server.
avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
Exctly.

Also jboss-log4j is fo jboss logs.
My aplication runs also without jboss. unit tests and etc and i dont want to have duplicate log4j fils.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by avihai marchiano:
Exctly.

Also jboss-log4j is fo jboss logs.
My aplication runs also without jboss. unit tests and etc and i dont want to have duplicate log4j fils.


have you tried what I have mentioned ?
avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
Not yet.

I understand that they solve the problem in JBoss 4.2

I hope to try this in the next few days.

How do i add it to the manifest?
(i buid with mavn2).

do you mean to add it to the manifest of each jar?

Thank you
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by avihai marchiano:
Not yet.

I understand that they solve the problem in JBoss 4.2

I hope to try this in the next few days.

How do i add it to the manifest?
(i buid with mavn2).

do you mean to add it to the manifest of each jar?

Thank you


Your EAR would have META-INF folder and that will have the menifest.mf file.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi,

I have two quotes from you avihai:

Originally posted by avihai marchiano:
My application deploy as an ear file.


and

Originally posted by avihai marchiano:
My aplication runs also without jboss


Which one is true now, maybe both of them are true . Is it now an EAR you deploy or not? If it is an EAR how can it run w/o an J2EE application server in this case JBoss? If it is not an EAR and more kind of standalone application or a client JAR then this is a different story. EAR is for JBoss , JAR is for a standalone or client application.

In case of an EAR, you are embedded in JBoss' infrastructure which includes Logging from that moment on you deployed it. In your code the only thing you need to do is to get the JBoss Logger with getLogger(yourClass). In case of a standalone or client application you need to write your own Logger first and put it in your JAR or classpath but not into your EAR.

So you must distinguish where you log client, server or both. I don't think that you can mix server and client, because JBoss has its own server.log where only server stuff including your EAR are logged. For all client stuff you create and use your own log file and Logger. While the server log file reside on the server you keep your client log file on client side.

Regards,
Darya
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by avihai marchiano:
My aplication runs also without jboss

I guess by this he means that his application runs on some other application server too.
But its just my guess.
avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
Both true. I will explain.

My application deploy as a ear,

But i can run some of the project that deploy at the ear in stand alone mode (for unit testing).

no, i dont mix the client and server.

lets say i have common,serverInfrustrcutre (depend on common), server(depends on both). i can run unit testing against each project.
In the loging i dont want to log the client (this is another log4j file). i want to have the log definitions like i run it onb the server.

I thing the application need to have its own logging seperate from jboss loging definitions.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Originally posted by Rahul Bhattacharjee:
I guess by this he means that his application runs on some other application server too.


I think these app servers all work quite the same. Let it be xyz-log4j.xml instead of jboss-log4j.xml (JBoss 4.2+) in case of another app server.

Regards,
Darya
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Originally posted by avihai marchiano:
My application deploy as a ear,

But i can run some of the project that deploy at the ear in stand alone mode (for unit testing).


Can you explain it in more detail. How does your standalone mode and how does your unit testing look like?

Regards,
Darya
vidya mahavadi
Ranch Hand

Joined: Nov 24, 2004
Posts: 34
Hi guys,

I am working around the same problem of separating the log4j properties files in jboss. My stuff is working fine when I add the appenders to jboss conf/log4j.xml and now I am trying out the option that Rahul suggested. I am using maven for building the project and I have put the log4j.xml under src/main/resources/conf folder and the packaged jar has the correct path as conf/log4j.xml. Now how do I add this file to the Class-Path in manifest.mf. my plugin settings in pom.xml are as follows.

<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>

It is adding all the dependency jars to classpath, but not log4j.xml. Any ideas how to get this thing to work?

Regards,
Vidya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to have my own log4j.xml file in Jboss