We help IT Professionals succeed at work.

How to log java errors in tomcat

Kevin B
Kevin B asked
on
177 Views
Last Modified: 2017-04-04
I have a java application that is not running properly on a tomcat server.  I see catalina-date.log, localhost.-date.log, localhost_access_log.date.txt, localhost-date.log, manager.date.log and host-manager.date.log in the logs folder of tomcat.  None of these files contain any java errors I would expect to see...

What is the easiest way for me to add logging in tomcat?
Comment
Watch Question

rrzstudent
CERTIFIED EXPERT

Commented:
What specific errors are you talking about here?  
I always found the command console and catalina-date.log adequate for my development work. Did you read
http://tomcat.apache.org/tomcat-8.5-doc/logging.html 
?

Author

Commented:
I am selecting information from a DB but nothing is being returned.  I don't see any information as to why that is so I was hoping to add some logging to assist in debugging or at least to assist in determining the error.
student
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Yeah I did... here is some of the database code.  This is a very simplified version of what I'm trying to do.... a method returns "The price is (price) for this item"
Unfortunately, it just returns "The price is for this item"

This would strongly imply that it's getting no results from the DB... but I've tried to run this query directly on the DB and it returns results fine.  I also don't see that sysout in catalina.(date).log

	        System.out.println("The customer results will be printed");
		Connection conn = DriverManager.getConnection(url, props);
		Statement statement = conn.createStatement();
		
		
		ResultSet rs = statement.executeQuery("select price from public.customer_rating");

		String price = "";
		while (rs.next()) {
			price = rs.getString("price");
		}
		rs.close();
		conn.close();
		return price;

Open in new window

rrzstudent
CERTIFIED EXPERT

Commented:
I also don't see that sysout in catalina.(date).log
You should see that printed in the command console that started Tomcat.
We need to see more of your code. How do handle Exceptions? The code that you posted should be placed within a try block and followed by a catch block. Furthermore, most people close their statements and connections in a finally block.

Author

Commented:
Hey, I was able to get the logging to work.  The error message that I see is "No suitable driver found for jdbc:postgresql://10.233.1.40:5432/postgres"

I am using maven and the driver seemed to work fine locally.  I have deployed the same version of the postgres db on the server and I am getting this error.  Is there a specific place I need to put the postgres jar?  Are you aware of that?  It's possible I need to start a new forum for this because the logging issue seems to be resolved.
rrzstudent
CERTIFIED EXPERT

Commented:
You might have to start a new question that addresses your database problem.
Where in your web app did you place the postgres jar?

Author

Commented:
When I built it, it placed the jar in WEB-INF/lib

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.