Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

logging with Java logging API in j2ee???

Status
Not open for further replies.

georgehategan

Programmer
Oct 4, 2004
3
RO
Hello everyone... I have a little problem about including logging.properties file for java logging API in j2ee application running with jboss. What other settings do I have to do in order to make it work. I have worked with logging API for simple java applications and used the -Djava.util.logging.config.file=myfile argument that was working fine but there has to be something else with j2ee applications. Please give me some ideas. 10x a lot. G
 
What problem/error exactly have you got ? Which JBoss version ?

Have you tried using :

System.setProperty("java.util.logging.config.file", "myfile");

JBoss uses log4j to do all its logging, so you might consider using that.

--------------------------------------------------
Free Database Connection Pooling Software
 
Actually I got no error because I didn't know how to include that file (System.setProperty...)
I know that Jboss uses log4j but still want to use java logging api. Another question... Where do I have to use System.setProperty? I suppose not in every file that instantiates a Logger, but somewhere where it runs just once. I thought it might be included as xml element or something like this. Thanks for your help and I am waiting for your answer. All the best, G.
 
In your application I would have a simple class like this :

Code:
public class InitializeLogger {
  public InitializeLogger(String file) {
    System.setProperty("java.util.logging.config.file", file);

  }
}

And then in your application, create a static intstance of the class, so that it is only ever loaded once :

Code:
static InitializeLogger il = new InitializeLogger();

--------------------------------------------------
Free Database Connection Pooling Software
 
Or rather :

static InitializeLogger il = new InitializeLogger("myfile");

--------------------------------------------------
Free Database Connection Pooling Software
 
It looks ok to me. Last question... I hope... :) Where do I store my .properties file inside the war|ear|jar? and what relative path should I use? Regards, G
 
You can store it wherever your like - it depends on the type of application & how you intend to use it - I have no idea if java.util.logging classes can read a file from within a jar file, so I guess you will have to do a bit of trial and error ...

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top