J2EE and Standard Java Application Log4j.properties - log4j

I have a project folder with merged J2ee application and standard java application. I am having trouble with configuring the Log4j.properties. I want to have separate log files 1 for my web application and another 1 for my standard application. I have two Log4j.properties files one under the root package of my web application and one under the root package of my standard application where both packages are under src folder.
When I ran both web app and standard app specifying only the file name, the log file for my webapp is created in the web server directory but my standard java app log file is created inside my WAR directory. I want the log file for my standard java app and my web app to be placed in the root folder that is why I specified in both log4j.properties absolute path to that folder. The problem is the only created log file depends on which log4j.properties file was detected and logs for both my web app and standard java app was written on that one file

This will be a detective work since I'll have more questions than you did.
I have a project folder with merged J2ee application and standard java application
This distinction seems to me a bit blurry. You have one project folder for two applications? It would be easier if they were separated. Is your standard java application a standalone application that can be run on a command line? A set of utility classes like a library?
I want to have separate log files 1 for my web application and another 1 for my standard application
I believe here lies your problem. If you're using your standard application's libraries in your web app, then during loading the application server will find two log4j.properties files on the classpath. You can not be sure 100% how this will behave.
When I ran both web app and standard app specifying only the file name, the log file for my webapp is created in the web server directory but my standard java app log file is created inside my WAR directory.
Running a web app specifying only the file name is unclear. What file name? When you say your WAR directory, do you mean the directory of your webapp, that's also inside your web server directory, or the directory under your (I'll assume you use Eclipse) IDE's project folder?
I want the log file for my standard java app and my web app to be placed in the root folder that is why I specified in both log4j.properties absolute path to that folder.
Root folder, like / in *nix? If you want them both to be placed in one folder, then you should remove one of log4j.properties files.
The problem is the only created log file depends on which log4j.properties file was detected and logs for both my web app and standard java app was written on that one file
Yes. You need to have only one log4j.properties file.

Related

unable to find log file after a spring boot application is deployed on an external tomcat 9 server

My recent web project is built using spring boot and packaged as a .war file.
I've deployed the .war file on an external tomcat 9 application server, which runs on a debian machine. The deployed application runs fine, except that I can't locate the log file. The logging information is important to this project.
This config snippet is in the project application.properties file.
# logging
logging.file.path=dev-logs/
logging.file.name=dev-logs/project_name.log
logging.level.root=INFO
For my classes that need logging important information, I use #Slf4j which comes from import lombok.extern.slf4j.Slf4j; to annotate the class and simply use methods like log.info() or log.error() where the logging actually happened.
During development, the log file and the dev-logs folders are all generated under the project root folder and the log file has real logging inside.
But the .war deployed to external tomcat, I can't find the log file.
It seems though that the catalina.out file in /var/lib/tomcat9/logs/ has the loggings, but shouldn't it be named as project_name.log?
Is this because my config about logging in application.properties is wrong? or I just searched the wrong place.
Please help, thanks.

Liferay projects building in wrong deploy folder

Working with liferay and portlets from last 3 weeks.
I downloaded the bundled liferay server and placed it on my local drive.
I did the set up and was able to access localhost:8080 properly.
I also created some custom portlets and when build them in eclipse the war files were getting deployed in the path C:/liferay/deploy.
Now, I changed the server location, I wanted to have the server in D:/ drive.
When I did the transition, started the tomcat server from D:/liferay/tomcat/bin/startup.bat
and then build the project, the war files are still building in c:/ drive.
When I copy the war file manually from c:/liferay/deploy to D:/liferay/deploy it gets deployed successfully.
I want the war file to be created directly in the d:/liferay/deploy folder.
Can someone help me understand what all changes do i need to do here?
If you are using Liferay plugin sdk then there would be file named as
build.<userid>.properties
in your plugin sdk.Change the below properties as per new configuration and give a try
app.server.portal.dir
app.server.lib.portal.dir
app.server.lib.global.dir
app.server.deploy.dir
auto.deploy.dir

logging 2 web apps to 2 different files

I have 2 web applications built from the same source tree within tomcat, which each use a PropertyConfigurator loading their respective /webapp/WEB-INF/classes/log4j.properties.
Currently tomcat is configured to use one console appender for the whole container, and both app's log4js just write to the console:
log4j.rootCategory=info, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
This means I end up with one big catalina.out for the whole container.
I would like to configure each of the applications log4js so that they append to their own separate rolling files.
I'm aware I can use system properties substitution within log4j.properties however isn't system properties shared across the VM and therefore not threadsafe between the 2 applications within the container?
Can someone suggest a tidy solution which allows me to configure the 2 applications to log to separate files, preferably with the application's context name within the log's file name.
thanks, p.
Where is your log4j.jar and commons-logging.jar placed in tomcat directory? And which version of tomcat you are using?
If you have one copy of these jar inside common/lib than surely catalina.log would be used by all logging since tomcat's log4j.properties file is only the one getting configured for both server and webapps under it.
Assuming this scenario holds valid in your case, copy log4j.jar and common-logging.jar under WEB-INF/lib for both web applications.
For using application name within log's file name, since separate log4j.properties file is used for each application, name your logfiles as you like in log4j.properties file against FileAppender or RollingFileAppender.

How to deploy a data file on tomcat web server in linux debian OS

I have a web application developed using JSP and Servlet. This web application is deployed on server having Debian Linux as OS and The Tomcat version is 5.5.31. As this applications required some data files, These data files will be get created automatically when setting are done using a standalone java application. This application is deployed on another machine. This setup is done. As I dont know much about Debian Linux and where my application is goes on it so I have some doubts in deployment of these autimatically generated data files which are as follows
As I made the .war file of my web application and deployed it using Tomcat Manager. so I dont know where exactly my application goes. I dont know the exact path. How do I find it?
Is it possible to create FTP for this web application which is deployed on Debian Linux server? I think that if creating FTP is possible then I will directly connect to FTP using my Stand alone Java program and will easily do the creation of the file and other file and directory manipulation.
If you've deployed a war, the application isn't anywhere on the filesystem as such. Most servers will unpack the war somewhere, but you shouldn’t rely on where that is.
I can think of several options:
getServletContext().getAttribute("javax.servlet.context.tempdir") to get the application's temp directory, then inform you external program of this location and place the file somewhere in there in a know location.
Arrange for a "know location" outside of the application, such as /tmp/somewhere or /var/cache/your-app/somewhere to place such files. (Note: /tmp is usually cleaned on startup of a linux machine)
As for getting the file onto the server from a remote machine: You could get your client to upload the file directly to your webapp (something like Apache HTTPClient will help you there), which means that you could do without the "know location" above. If you want to do this outside of the application though, I'd avoid FTP (due to security). Instead, I'd go with scp (secure copy).
Edit: Reading between the lines a little, you mention "setting" in the data file. If this is a configuration file which is not changed once the app is running, you may find it more convenient to have a "deploy" step on your server which simply takes the settings file and adds it to the war before deploying it. This is easy enough with "ant war" for example. You could then access the file using getClass().getResourceStream(..) or such.

Access file in weblogic server

Is there a folder in the Domain Directory of Weblogic, where files put inside can be accessed directly from web browser? In other word, I don't have to pack the file in an ear, war file and deploy it to make it accessible?
Thank you very much
Regards
K.
The Virtual Directory Mapping feature (that you declare in the weblogic.xml) would do the trick:
Using the virtual directory mapping
feature, you can create one directory
to serve static files such as images
for multiple Web Applications. For
example, you would create a mapping
similar to the folowing:
<virtual-directory-mapping>
<local-path>c:/usr/gifs</local-path>
<url-pattern>/images/*</url-pattern>
</virtual-directory-mapping>
A request to
http://localhost:7001/mywebapp/images/test.gif
will cause your WebLogic Server
implementation to look for the
requested image at:
c:/usr/gifs/images/*.
This directory must be located in the
relative uri, such as
"/images/test.gif".

Resources