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
Related
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.
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.
Our project consists of 3 webapplcations that communicate with each other via web services.
All 3 web apps are running on 3 different web servers that run as a cluster with load balancer. (spring , tomcat, mysql)
Our CTO mentioned that in production, it can be very helpfull to invistigate errors on log on a single unified log file that is consist of all the webapplication log files combined together.
this way it is very easy to see in the log the whole flow across the webapps and not skipping from one log file to another (for each webapp log)
after a quick research we found that combining all the logs into a single file may cause corrupt file error of the log file itself. (we are using slf4j with log4j configuration)
So basically we have 3 questions:
1) Is it a good practice to combine all of the web apps log into one?
2) Whats the best way to achieve that (non corrupted log file will be nice)
3) Is it possible \ relevant to do the same concept of log unification in regard to tomcat logs? (unify all unified logs of all tomcats in the same cluster)
Logging to the same file from multiple servers can get very messy. You inevitably end up with multiple servers attempting to update files simultaneously, which has a habit of causing problems such as weirdly intermingled output and locking.
Given that you're using Log4J, then you should check out JMS queue appenders:
http://logging.apache.org/log4j/2.x/manual/appenders.html#JMSQueueAppender
Using this, every server logs to a JMS queue, and you can set up a listener which logs to file on a separate server.
A reasonable alternative would be to do a little bit of Perl scripting to grab the files and merge them periodically, or on demand.
You will probably find messages which are out of step with each other. That's because each server will be buffering up log output to avoid blocking your application processes.
Logging just the errors to a common place is useful. You can continue to log to each application's log, but you can add remote logging for selected entries (e.g. anything with Level=ERROR).
The easiest way to set this up is to run a SocketServer on one of your machines.
Here's an example that shows how to configure it.
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.
We have load balancing and the same name on multiple instances of WebSphere 6.1.
Is there a way to WebSphere need to add the physical hostname to the WebSphere SystemOut.log lines (for example, to prepend to every line)?
Thanks, Bert
I assume you are trying to see how the load is distributed across all the WAS Instances (in a cluster as you had mentioned load balancing)
Is that a web application that you are working with?
If yes the cloneID would give you the answers. Each Server in a cluster is given a unique clone ID.
Look at the Web Server's plugin logs and see which server received the request.
This can be used for a Web Application to see which server serviced the request.
HTH
Manglu
You can implement a custom log formatter and handler and attach them to the root logger. It should capture everything and you should be able to decide the complete logging format and location. The example is for 6.0 but the example should be still valid.
Alternatively you could implement similar log formatter and configure the JVM logs to use custom log format.