Hi Guilherme,
you can package the log4j.config-File in your ws-archive.
There it doesn't matter where the file is located. In my case it's the
config-folder and I use JDOM to load the config-file.
Then you use something like this to init your logger:
private static final String LOG4J_CONFIG = "config/log4j-config.xml";
/**
* Initialize log4j
* @param service reference to ws
*/
private void initLogger(AxisService service) {
ClassLoader loader = service.getClassLoader();
InputStream is = loader.getResourceAsStream(LOG4J_CONFIG);
Document log4jConfig = null;
try {
SAXBuilder builder = new SAXBuilder();
// log4j.dtd shouldn't play a part...
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
false);
log4jConfig = builder.build(is);
// from JDOM to DOM, to load the config
DOMConfigurator.configure(new
DOMOutputter().output(log4jConfig).getDocumentElement());
} catch (JDOMException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
The only thing it's to get a reference to the AxisService.
That's the way it works for me.
but if you use more than one ws in axis, maybe all services log to the one
log-file.
So perhaps you have to do anything with your log4j-config and the appenders to
use various log-files.
Thanks,
Markus
-----Ursprüngliche Nachricht-----
Von: Guilherme Fré [mailto:[email protected]]
Gesendet: Mittwoch, 14. Oktober 2009 14:49
An: [email protected]
Betreff: RES: Using Axis2 with Log4J
Hi Markus,
Actually, now it's working, but not the way I want it.
I have put the log4j.xml file into the folder ..\Tomcat
6.0\webapps\axis2\WEB-INF\classes.
It worked fine, but all the axis web application is being logged using this
configuration file.
I'd like to know if there is a folder where I could put the configuration
file so that it's only going to be used by my web service.
Or, if it is not possible, perhaps a way to define in the file that those
options might be used uniquely by my web service.
Thanks,
Guilherme
-----Mensagem original-----
De: Grimm, Markus [mailto:[email protected]]
Enviada em: quarta-feira, 14 de outubro de 2009 03:09
Para: [email protected]
Assunto: AW: Using Axis2 with Log4J
Hi,
can you give us more information?
why it seems, that the ws can't use the config-file?
how and where do you initialize your logger? ...
Thanks,
Markus
________________________________
Von: Guilherme Fré [mailto:[email protected]]
Gesendet: Dienstag, 13. Oktober 2009 22:29
An: [email protected]
Betreff: Using Axis2 with Log4J
Hi guys,
I have developed a ws and it's working pretty fine. But I'm not able to log
my application using log4j.
Can someone tell me what exactly is necessary for me to use it?
What I've already done is: I created a log4j.xml and put it into the
properties folder of my application. Running from Eclipse, it works fine.
But it seems that when deployed, the web service cannot use the .xml file to
log into the application.
Does anyone knows what is happening??
Thanks in advance,
Guilherme