I have a web app written with the java/spring/hibernate stack, and I have several pieces of code in the app that print out debugging information. For example, I have hibernate's "show_sql" attribute set to "true" so that it shows me the queries it is executing. Another example is whenever an exception is caught, its stack trace is printed out to console.
Now, I have moved my WAR to the production server which is running tomcat 7.0.42. However, I am having a problem getting hibernate or mysql queries to execute, so I need to debug the problem. But the problem is catalina.out only shows very minimal messages; There is no hibernate output or error stack trace. In fact, none of the logs in the logs/ directory show output from hibernate or exception stack traces.
So my question is how do I get the same output on the server as I get when I'm running my web app locally?
Assuming you're logging to System.out or System.err, fiddle with logging.properties in ${catalina.home}/conf
If you're using a proper logger (you should be!), I would have to imagine you need to fiddle with the appropriate config file for that logger.
Hibernate's show_sql prints to standard output System.out. If it's not in logs/catalina.out, either the parameter is false or you've setup Tomcat to direct System.out to some other place.
Related
I have a java server application running that uses Logback as its primary logging library. Recently I asked a developer to remove the extra console logging they had added for a non-development environment and when they asked me why realized I didn't have solid reasoning for it.
The extra logging I believe would cause more I/O operations but does it also add more memory usage? How large is the buffer that it's writing to in stdout and when is that cleared?
Our standard logging is to a file which we can view or also have it piped into monitoring tools. The application is deployed via an automated process and is headless so generally no one is on the VM looking at things.
Example logging appenders (Dropwizard configurations)
logging:
level: INFO
appenders:
- type: file
currentLogFilename: /var/log/myapplication.log
archive: true
archivedFileCount: 5
- type: console
target: stdout
Essentially, is there a detriment to logging to the console when not using it and what does that take the form of?
Unless you are logging millions of records, logging has no noticeable impact on performance.
Logging to the console is more ephemeral than logging to a file--the log messages are not saved anywhere. This makes it impossible to track down errors and troubleshoot problems, especially in production.
Logging to STDOUT can be useful if you run your application inside a container like Docker. Docker can fetch anything written to STDOUT and STDERR in any container it runs using docker logs or can redirect to a different server. If the application would write to a logfile local to the container it runs it, it would be much more difficult to access this file from outside the container.
Not able to run mongodb instance in ERROR log level. As defined by mongodb documentation, by default verbosity is 0 which includes information messages. But increasing verbosity to 1-5 will include debug level messages. I need only error messages to be logged in my log file. I am currently using mongodb-3.6.3 version with java driver at client side.
Is there any way to do it? If yes, how to achieve this? I've already tried reducing logs by adding quiet = true in the config file. But still, a lot of unnecessary logs are generated.
Add this line to your application.properties file and check the console output after running any MongoRepository query.
logging.level.org.springframework.data.mongodb.core.MongoTemplate=ERROR
i am using log4j to write logs to a file.
My application is multithreaded.
While the program executes i can see the logs on console but when i open the configured log file where the log was supposed to be written, it contains only a few logs and rest of the logs are missing.
Can anyone please suggest anything i need to check as what might be causing the issue.
Also, the same log4j.xml config file when used in simple (not threaded) application works fine and prints out all logs to the desired file.
I'm using Log4j in my application and application logging is working fine while framework in my application is internally using commons-logging and logs are going to System.out but I want to redirect them to a separate file and also want to enable DEBUG level.
Tested this on tomcat and working fine. Generating all logs in their respective files. But when I deploy code on WAS7.0, only INFO level of framework logs are being generated SystemOut.log. (my log4j.xml is fine as it is working fine on tomcat)
Any help would be appreciated. Thanks!
I was having the same problem. I found the answer in Websphere Docs.
Note: Trace information, which includes events at the Fine, Finer and
Finest levels, can be written only to the trace log. Therefore, if you
do not enable diagnostic trace, setting the log detail level to Fine,
Finer, or Finest does not effect the logged data.
Reference: http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.base.doc%2Finfo%2Faes%2Fae%2Frtrb_loglevels.html
In Java Utility Logging terms FINE = DEBUG, so DEBUG level and below will not appear in System.out, only int the WAS trace log.
I am using Log4j logging framework to insert the log into oracle database.But the insert query in the log4j properties file is taking a lot of time to execute and making the application very slow.When I removed the logging statements from the java code, the application worked fine.At first, I thought that the insertion into DataBase is taking time , but writing the log on an external file also takes a lot of time.
Can anyone please suggest a solution?
Thank You,
Dhaval Maheshwari.
If you application is under development then log level should be debug and before logging you should check for isDebugEnabled() and then log your string.
but If your application is in production then log level should be info and you must log minimal information in log file.
Always use atleast two log level in your application one for debuggnig
mode(for development environment) and another for production mode and
production log should be minimal.
This is the way you can speed up you applicaiton.
and second thing if you want to persist your logs into database then
create a scheduler task whose responsibility would be reading logs
from flat file and persisting them into database and schedule this to
run only once in a day.
I suggest not to follow the technique u r following now.
First of all I am not sure why u r trying to log the output of log4j in DB.
Anyways if it is that necessary try something like this. Let the logfile write into a file as it is and later run a thread to dump this file from the disk when file is closed to the database as a batch process.
In this case your application will be separated from the latency of DB.
There are other solutions also using a JMS.
Where you can write it to a JMS queue and the consumer on the other hand can read the queue and write it a DB.
It depends on the kind of problem you are trying to solve though.
See of it helps
In Logging there are levels included in. For example in production only log application level exceptions and errors[ERROR level].
If it's tracking logs(Such as user actions) don't write them to files, directly add them to database. Hope this helps.