Kevin B
asked on
How to log java errors in tomcat
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?
What is the easiest way for me to add logging in tomcat?
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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
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;
I also don't see that sysout in catalina.(date).logYou 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.
ASKER
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/p ostgres"
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.
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.
You might have to start a new question that addresses your database problem.
Where in your web app did you place the postgres jar?
Where in your web app did you place the postgres jar?
ASKER
When I built it, it placed the jar in WEB-INF/lib
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
?