Specify log settings for axis 1.4 - java

I have a java app and I'm using axis to make soap calls. Does anybody know how I can tell Axis to use my log4j.xml file located in my projects base directory instead of its internal properties?

Just make log4j.xml available in your classpath and log4j will pick it up. I know the name it looks for is log4j.properties if you are using properties file but not sure what is the standard name it looks for when you are using xml based configuration.

Related

log4j2 replacement for RollingFileAppender that set log directory programmatically

We are upgrading our Java application from log4j 1x to 2x.
In 1x we had an extension to RollingFileAppender specified in log4j.properties. As well as rolling the files, it would compute the path of the logs directory according to whether it was running in JBoss/Tomcat/Webserver, and file the logs there with a specific name.
It is not possible to extend RollingFileAppender in 2x.
My question is: What can I specify in log4j2.properties (or XML if necessary) that will allow me to set the log directory programmatically as before, and roll the files.
It's something like this question, but without having to set up an Environment Variable for every installation, if possible.
Log4j2 customize file path with rollingFileAppender (Java)
Log4j 2.x is very extensible. In your case you can write a StrLookup that computes the parameters you require and annotate it with:
#Plugin(name="some_prefix", category="Lookup")
The class must be compiled using the annotation processor in log4j-core and can be used in a configuration file as:
${some_prefix:key}
where key is the value that will be passed to StrLookup#lookup.

get location for log4j config stored outside application

We are doing a maven project which is using datanucleus which logs with log4j so can't use logback. Where can I put the log4j config file outside the application so that the different VM environments have access to it. How can I get the location of the config file without hard coding the classpath?
You could specify the path in log4j.properties.
log4j.appender.file.File=path_to_log_file
For details, please check this example.

How to read Logback configuration file from path outside the war file?

I have a requirement where I want to place all logback configuration outside the war file.
Presently I have placed my configuration file (logback.xml) on the classpath.
I am using the JBOSS EAP web application server, kindly suggest how to achieve the same.
Go into the jboss startup/run script and add this option:
java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1
see more at http://logback.qos.ch/manual/configuration.html
You could also use -Dlogging.config=/path/to/logback.xml
This is really handy with java based microservices to provide logging XML externally.

Logging in web application deployed as WAR

I am coding a Java web web application packaged as war and I would like to add logging and specify the log folder to write log files to (using configuration file, e.g. logback.xml)
Obviously, I would not like to configure the absolute path of the folder. Now I wonder how to configure the log folder in war. What are the best practices and recommended approaches to this?
We use to use relative paths in logback.xml but changed to using an env property. When the path was relative we could never tell the customer exactly where the log file was due to different Java EE server implementations. Using an absolute path with an env variable made it easier. For example
<file>${user.dir}/logs/my_web_app.log</file>

Can I use log4j in a web app with a file other than log4j.xml or log4j.properties?

Is it possible to use something other than the file names log4j.xml or log4j.properties to configure log4j logging in a Java web application?
I want to load a log4j.xml file from a different location on the file path (not in my classpath). Is that possible in a web application using say, JBoss or Tomcat?
You can use PropertyConfigurator.Call configure with file you wanted
Use -Dlog4j.configuration=path/to/your/file.xml startup parameter to specify where your configuration file is. It's the recommended practice anyway:
The preferred way to specify the default initialization file is
through the log4j.configuration system property.
(log4j manual)

Categories