Exposing Tomcat log files - java

Tomcat log location is :
/apache/apache-tomcat-8.0.15/logs
What is standard method of enabling access to these logs via browser ?
Is enabling Tomcat dir listing standard for this ?

I have seen similar setup done for one of the apps where I worked for an Australian telco whereby application logs are logged to a directory where Apache can serve them.
The pro is that it is really simple, just install Apache and most application developers are happy to download log files from their browser.
Just make sure the public does not access this directory.
The con being, if the log files are somewhat large that may take up quite a bit of bandwidth from your users.

Related

How Does One Deploy a Jersey Application to a Remote Tomcat Server

I need to state up front that I am not a Java developer. So it is fair to assume that I know very little about the tooling etc. that Java dev's will be naturally familiar with.
So, I have created a Jersey web api (2.25.1) on my home server running Windows 2012. It serves data to a Xamarin application. I need to deploy this to a Linux server (Ubuntu) on AWS which my friend spun up.
At the moment, the only access I have is via SSH (Putty).
Tomcat (and Glassfish) have been installed on the Linux machine.
How do I go about deploying that application to that AWS server?
The official Jersey documentation seems to be MIA, and my Googling efforts don't yield much. There's a lot of SO questions with a similar title to this one. But I have not found any of the answers (and in many cases, questions) helpful to my cause.
Cheers
I assume that you are using maven to create your jersey web app .
Upon build you will get a *.war file .Copy the same to tomcat/webapps folder .
Start your tomcat then.
To take your file there on remote use winscp tool with your ssh credentials.

Live web log viewer for tomcat catalina.out

With a standard webapp running in Tomcat with the Spring Framwork and Log4J logging to catalina.out I need to have a better access to logs than manual SSH and tail -f catina.out
I already know of some solution like logstash, ... but they require to send the log to a centralized server. I went through a lot of answers of various websites but none satisfies my needs. I just want to have access to the logs in a web browser on the same web server.
Is there any simple and straightforward way to do that ?
Update
I want to to that because I cannot always SSH and tail -f the logs because of the firewall IP security. I need to be able to see these logs from anywhere as long as I have an internet access to such a secure live web console.
Give logsniffer a try. It's a simple standalone Java web application which can run on the same host. log4j log format is supported out of the box, just type in the conversion pattern and the logs will be parsed properly. You can tail, search and monitor the logs in real-time. Last but not least, logsniffer is open source.
Disclaimer: This is my own project.

Can i write log to another machine in the network?

I made a web app with a ServletContextListener that in its contextInitialized() just calls two methods from two jars. The jars use log4j to print logs in its execution, what is useful for me on testing. Now, I package this app in an ear file, and deploy into a WAS, that is located into a server to which I don't have access (meaning, I can't access FTP to see paths on the server, etc) to set the path for the logs in the server, and it will take some time to get actual permission to set this.
I thought that maybe I could set log4j to print the logs in my working machine (that is also connected to the network the server is connected)
Is there anyway to do this?
Log4j has many appenders: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Appender.html
For Log to different machine you can use SocketAppender. But for yours situation better store logs in database with JDBCAppender

show progress in command prompt when java web application is running

I have developed a simple application such as insertion, updation in jsp,servlet that is java web. What i want to do is: suppose i am inserting data into my oracle db then data is inserted and i got a message that data has been inserted successfully, same thing i want to show in a command prompt when my web app is running in tomcat server. Application will run in browser and simultaneously command prompt will show that :
this data is inserted into this table---transaction committed successfully----
How can i implement that? Any help is much appreciated
The vast majority of Java web applications use Log4j for logging.
To log messages to the server's console, use the Log4j ConsoleAppender class.
Normally you need to do little more than drop log4j.jar into your tomcat/lib directory, and configure logging with a log4j.xml or log4j.properties file, then have your servlets or jsps or controllers or services issue logging commands. There are many tutorials on the web that can get you started learning log4j with tomcat.
Oh and by the way, you can try plain old System.out.println() calls from a servlet, though this is only for learning. Professional applications should use a logger.

What domain files would an application running in Glassfish have access to?

I'm working on a beta release of an application. This is a Java app that runs on Glassfish. Obviously we are getting bug reports from time to time. I would like to provide my users with a simple one-click button to get the server log from /domains/domain1/logs . I am not sure if the application is sandboxed in such a way that it can get to this log file.
Does glassfish sandbox the application in such a way that I would be prevented from getting the file? Is there a standard method or library I can use to get the logs?
If the file permissions on the server are correct, can I just have my application read the file using an absolute path?
You application can read the server.log file directly. Note that the logs are rotated, so your application would have to reload the log file and maybe even provide access to the rotated logs.
If you are using a web server front end, such as Apache, you could just serve the log directory. I think you could just create a symbolic link to that directory in your webroot.
Be careful you are not logging any sensitive information as exposing a log file could be a security risk.
If you are using GlassFish 2.1, you should look at AMX. The AMX class Logging seems to have the data that you want.
If you are using GlassFish 3.1, you should use the RESTful interface to the admin data. If you have an instance of GlassFish 3.1 running locally, right now, you can click this link to see the log data: http://localhost:4848/management/domain/view-log...
If you are using a WebKit based
browser, like Chrome or Safari, you
probably need to view the source of
the 'empty' page....
If you are using GlassFish 3.0, you will need to open the file directly.

Categories

Resources