Log4j with tomcat
Hi All,
This is my first post here ..yeahh !! :)
anyway..am on my way learning JSP / Servlet....and having trouble cofiguring log4j with tomcat
I have a few conceptual questions...
1. In our production environment, I see server.xml in Tomcat (Tomcat4) being contains the log4j entries. Is this the right way of doing it? Should the logging rather be in a config file with the Webapp folder for each app? Since loggin for each invidal web app should be its own business. also adding entries to server.xml would mean redeploying every other application. I know I could ask this question directly to my Boss but I thought asking it here would give me many more perspectives.
2. How to I go about configuring log4j with tomcat4. I have the log4j.jar file in the lib folder..where do I put the xml (config file for log4j) ? Also is that all I have to do to get logging enables?
I know my questions are a bit naive...but am just starting to learn this stuff...
Pease comment
Regards,
V
Hi there,
These are really Log4J related questions.
I think one way of setting up Log4J is to use a log4j XML file (equivalent of log4J properties file) , and place it under your project's
WEB-INF\classes\folder
Then place log4j.jar and probably Apache Commons Logging Jar file under your project's \WEB-INF\lib\ folder
That's it.
Read the docs here: http://logging.apache.org/log4j/docs/ or search them if you have additional question.
If your questions are not answered on the docs or Google search then check with the Log4J User Mailing List here:
http://logging.apache.org/site/mailing-lists.html
Scroll down to log4j-user list
Similar Messages
-
Using Java Logging with Tomcat
Hi in a previous non Tomcat project I wrote some classes that used the java.util.logging library that comes with java 1.4 quite successfully. I am now trying to use the same classes with Tomcat 5.0 but it doesnt like it. With the logging classes you can provide a configuration class which you define with a property "java.util.logging.config.class", I put the class in my WEB_INF\classes with all the other classes.
When I run with Tomcat i have a servlet that does the following to try and initilse the logging
com.appserver.util.logging.LogProperties.setLevelFromParametersFromPrefs();
System.getProperties().setProperty("java.util.logging.config.class", "com.appserver.util.logging.LogProperties");
LogManager.getLogManager().readConfiguration();
it complains it cant find the class, when running readConfiguration(), (The 1st two lines run ok). I think the problem is to do with Tomcat classloader, with a simple Java application the classes would be expected to be on the system classpath, but on Tomcat the system classpath only contains bootstrap.jar.
I realise I could probably get things working using Apaches log4j instead but it seems a bit silly to use that when there is a perfectly adequate logger built into the language now.
Anyone done this ?OK
Ive changed my code from
com.appserver.util.logging.LogProperties.setLevelFromParametersFromPrefs();
System.getProperties().setProperty("java.util.logging.config.class", "com.appserver.util.logging.LogProperties");
LogManager.getLogManager().readConfiguration();to
com.appserver.util.logging.LogProperties.setLevelFromParametersFromPrefs();
LogManager.getLogManager().readConfiguration(com.appserver.util.logging.LogProperties.getPropertiesAsStream());Now I dont get any errors and only messages for the LEVEL is set to the value I specify in my LogProperties class are displayed. However I also specify a Formatter to use for console output but Tomcat just seems to ignore it and uses its own default formatter. Any ideas...please ! -
Installing Log4J in Tomcat and using JDBC to log errors
Has anyone figured out how to install Log4J in Tomcat and use the Log4J JDBC functionality?
I have log4j.jar in CATALINA_HOME/common/lib.
I also have log4j.properties is in CATALINA_HOME/common/classes
Then when I start Tomcat I get the following error:
[main] DEBUG org.apache.commons.digester.Digester - addRuleSet() with no namespace URI
is it something to do w/ the log4j.properties file? do i have to use a xml format or is it ok to use .properties format?
-KarthikI would say you have something wrong in your log4j properties file.
properties format is fine, but I suspect something in there is not quite right.
Try starting with a simple example one, see if it works, and then try adding your own config based on that one.
Good luck,
evnafets -
Hi,
I'm trying to get log4j to work with tomcat, but for some reason none of the logs get written to the logfile.
I have a logfile containing:
<appender name="apachelog" class="org.apache.log4j.FileAppender">
<param name="File" value="${catalina.home}/logs/junk.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p (%F:%L) - %m%n"/>
</layout>
</appender>
<logger name="org.apache.jk.common.ChannelSocket">
<level value="info"/>
<appender-ref ref="apachelog"/>
</logger>
...Except the tricky thing is that though I don't have access to the source code for this jk.common class, I'm getting a ton of "INFO" logs from it, and I don't want them showing up on the console.
I've tried adding a line logger = Logger.getLogger("org.apache.jk.common.ChannelSocket") in my classes, but that doesn't work. In fact, under tomcat, I can't even get logging working for my other classes!
The logfile is getting picked up by tomcat (If it isn't configured properly, tomcat gives me errors on startup). The specified log folder is empty, and the output still goes to the console.
Can someone please help?
Thanks.It doesn't seem to work unless I actually call getLogger() & then call info manuallyI don't follow. What doesn't work? Your code always needs to call getLogger("somename") followed by logger.info("Some message"); in order to log an INFO message.
If only there was some way to associate a logger with a class during runtimeLogger's aren't directly associated with classes at all. Every logger has a name and by convension the name is the same as class that creates / uses it..
Logger.getLogger("com.somepackage.anotherpackage.MyClass");could be replaced with
Logger.getLogger("debugLogger");The reason for using the fully qualified class name is so that you can turn on/off logging by package or by class, e.g.
<logger name="com.somepackage">
<priority value="OFF"/>
</logger>Turns off all logging for every logger with a name that starts with "com.somepackage". The fact that just happens to be a package name is irrelevant.
I appreciate your help so far, but I'm really stumped as to why1)Logging happens to the console instead of the logfile
2)It bypasses the logger.info() method somehow
Tomcat uses commons logging, which in most cases uses Log4J behind the scenes. Is it possible you've instead managed to enable the logging that comes with J2SE? Download the Tomcat source, put a break point at the line that reads log.info( "connection timeout reached"); and see where it takes you when you step through. -
Tomcat vs Apache with Tomcat connectors (mod/jk)
Is there any advantage (security, performance etc.) of running a Java web application on Apache HTTP Server with Tomcat Connectors (mod/jk) rather than directly running it on Tomcat.
This question is already answered, see here:
http://tomcat.apache.org/faq/connectors.html
Also for Tomcat/ Apache related questions, post them to the relevant mailing lists. -
Problem with Tomcat 5.0
Hi there,
I have a .java file inside \WEB-INF\classes\ directory. This .java file has a "public static void main" method that calls al the other methods in the class.
I want to know if its possible for me to create an JSP file to call this .java file. If so how can i do it?
Thanks!!NerdVix wrote:
Hi there,
I have a .java file inside \WEB-INF\classes\ directory. Wrong. .java files do you no good in that directory. Only .class files belong there.
This .java file has a "public static void main" method that calls al the other methods in the class.Fine - for testing on a command line.
I want to know if its possible for me to create an JSP file to call this .java file. If so how can i do it?What part don't you understand? Writing JSPs? Calling methods? What is a person so ignorant doing with Tomcat anyway?
It's possible to call main, but not a good idea.
% -
HTTP 500 server error as follows:
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
An error occurred at line: 2 in the jsp file: /listStore.jsp
*line#2 is the usebean statement in the jsp...
NOTE: new machine, new configuration... this same servelt/jsp/bean work great on another machine with tomcat 3...
so this will have something to do with tomcat configuation... believe that the configuration is set to not compile with deprecation.. would like to know where to change that...I guess the problem comes from jdk 1.4 ...deprecation of sun.tools.javac.Main prevents compilation in jasper...
-
PDF with Tomcat/Cocoon Problem !!!
Hi,
I am having problem with Tomcat/Cocoon combination for APEX PDF printing which I installed following Carl Backstrom instructions.
When a report is a region report it all works fine, but when I create a report based on a query from the reports section in Shared Components choosing report layout 'Use Generic Report Layout' I get the following error.
javax.xml.transform.TransformerException: attribute-set named #TEXT_ALIGN# does not exist
cocoon://fop_post/xsl - 148:58
Cocoon stacktrace[hide]
attribute-set named #TEXT_ALIGN# does not exist
cocoon://fop_post/xsl - 148:58
I will appreciate any feedback. I saw threads related to the same issue on this forum but they ended up covering something irrelevant.
Regards,
VadimVadim,
Report queries and report region use the same generic report layout. However the processing is handled by different engines. The underlying technical problem with your case is that the substitution string #TEXT_ALIGN# is not substituted in all cases for report queries. This usually does not cause any problems, but appears not to work when using Cocoon.
I'll see that we can this resolved with the next version of APEX, however when working with report layouts, you would typically use your own RTF or XSL-FO stylesheets, where this problem would not occur. The option to use the generic report layout is only included so the data can be tested independently from the layout and is not really intended to be used as the actual layout at runtime.
The generic report layout function is mainly designed to be used for report regions.
Regards,
Marc -
Old Oracle Session with Tomcat is not kiiling automatically
Hi,
I am facing a problem of increasing inactive oracle sessions with tomcat, Old Oracle sessions with tomcat are visible with new one.
if somebaody did not restarted tomcat gracefully, then does Oracle keep the session connected or is there any way that whenever any one restarted tomcat abnormally, Oracle session can be killed.
I had restart the database to kill session.Could you please tell me that where do i set this parameter in parameter file or sql net file and what is the recommended value, do you have any document on this.
Another thing tomcat is in other server machine and my database is in different server machine, killing process in tomcat server machine manually may not kill linux process on oracle database machine and therefore oracle sessions are still there.
Is it possible?
Edited by: user605066 on 28-Aug-2008 04:59 -
Hi,
We are migrating an EJB application from Weblogic 8.1 to Weblogic 10.0
In the current configuration, we simply include the following in the server startup script, so as to specify the log4j configuration file, and this takes care of the logging part.
-Dlog4j.configuration=file:<complete file name>
The same thing doesn't work with WL 10. Is there any other (special) way of using Log4j with WL 10?
Note that inside the code, we use commons-logging to get hold of the logger as follows:-
org.apache.commons.logging.LogFactory.getLog(class)
I would be grateful for any help on this.
Thanks in advance.
Regards,
NeeleshTricky questions.. this problem needs more analysing. I see that you are on R27.6.0, we've come with a few updates to that one. Download the latest greatest and see if that works things out: http://www.oracle.com/technology/software/products/jrockit/index.html. If not, then report this issue to JRockit support (see how to below)!
Best Regards,
Tuva
JRockit PM
How to report to JRockit support:
You must register and file the issue on Metalink, http://metalink.oracle.com. Note that you must have purchased support to continue.
If you have problems during the registration or filing you can call our support +1.800.223.1711* or 1-800-633-0738 directly.
In case you have not purchased support call 1.800.833.3536* for support sales.
More information on our support site: http://www.oracle.com/support/index.html.
*) US numbers - for global technical support contacts see: http://www.oracle.com/support/contact.html -
JSP: work with TomCat 5.5.9 and NOT work with TomCat 6.0.16
Hi all,
I'm Antony and I have a problem with a .JSP page of my server.
In my server there are 2 users: "u1" and "u2"; there are 2 TomCat, version 5.5.9 and version 6.0.16. There is Apache WebServer version 2. The 2 TomCat servers have the same configuration files: server.xml and web.xml (in the dir /conf of the main server's root). They not work simultaneously.
When the user "root" launch the TomCat 5.5.9 all work fine: the server will show correctly the JSP pages of "u1" and the pages of "u2".
When the user "root" launch the TomCat 6.0.16 the JSP pages of "u1" work fine but the JSP pages of "u2" not work: it seems that there are problems with the path where the server want to search the pages of u2.
In the server.xml there is this code (for the handle of u2's site):
<Host name="u2site.com" appBase="/home/u2/public_html/">
<Alias>www.u2site.com</Alias>
<Context path="" reloadable="false" docBase="/home/u2/public_html/" debug="0"/>
<Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>
</Host>and this code (for the u1's site)
<Host name="u1site.com" appBase="/home/u1/public_html/">
<Context path="" reloadable="false" docBase="/home/u1/public_html" debug="1"/>
<Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>
</Host>The problems with the JSP pages of u2 are one of the following:
org.apache.jasper.JasperException: /login2.jsp(4,0) The value for the useBean class attribute com.u2.beans.access.Autenticator is invalid.and this one that appear with the pages that have the inclusion of another JSP page
/u2page.jsp(3,0) File "/../support/_formatting.jsp" not foundI think that the TomCat know how to find the page that the browser request to Apache WebServer (and that the webserver request to Tomcat by the connector) 'cause for pages that haven't inclusion or call to method in packages all work fine...but the TomCat have problems to locate the pages included or the method located in a JAR (the jars are located in WEB-INF/lib/ of the u2's site).
How I can resolve this problem with TomCat 6.0.16? I repeat that with TomCat 5.5.9 all work fine...same configuration!
Any ideas?
Thank you very much,
Antony.Hi stevejluke, 'cause in the page "/supporto/_formatting.jsp" there are only the definition of some variables it's normal that the output at the browser it's a blank page.
The problem it's that Tomcat 6.0.16 cannot know how "navigate" the pages beginning from one...it know where is the "x.jsp" page requested directly by Apache WebServer, where is "y.jsp" request directly by Apache, where is "z.jsp" requested directly by Apache but if "x.jsp" request, includes, "y.jsp" Tomcat cannot know where "y.jsp" is located. There is some file where I can "say" this to Tomcat?
The page "/mostre/elenco_mostre.jsp" includes directly the "/supporto/_formatting.jsp".
Another thing: in /mostre/elenco_mostre.jsp there is an inclusion directive for /supporto/_formatting.jsp that is so:
<%@ include file="../supporto/_formatting.jsp"%>you can see that the included file is "../supporto/_formatting.jsp" and NOT "/../supporto/_formatting.jsp"...the "/" at the begin of the path is included by Tomcat!
In the catalina.out there are this lines, when the page is called:
Jul 6, 2008 3:15:00 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /elenco_mostre.jsp(3,0) File "/../supporto/_formatting.jsp" not found
In catalina.out before server start there are this lines:
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '1' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '1' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '1' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '1' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '1' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '1' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Jul 6, 2008 1:43:49 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 358 ms
Jul 6, 2008 1:43:49 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jul 6, 2008 1:43:49 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.16
Jul 6, 2008 1:43:52 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/23 config=null
Jul 6, 2008 1:43:52 AM org.apache.catalina.connector.MapperListener registerEngine
WARNING: Unknown default host: localhost
Jul 6, 2008 1:43:52 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2512 msThe file "web.xml" is located in "$Tomcat_home/conf" and it's:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>there are not web.xml file in /WEB-INF/ of the web application.
Maybe the problem it's that Tomcat want the conf file in "Server/Service/Engine/Host/Context" ? I must move the block HOST of the server.xml file in this path?
Good Sunday and thank you!
Antony. -
Hi, we have Apache 1.3.19 intergrated with Tomcat 3.2.2 using mod_jk.
When we checked with the mod_jk.log file, the file size is very large for just turning on it for 5 days. And the contents of this file are repeating the following two lines:
[jk_uri_worker_map.c (185)]: In jk_uri_worker_map_t::uri_worker_map_free, NULL parameters
[jk_uri_worker_map.c (335)]: jk_uri_worker_map_t::uri_worker_map_close, NULL parameter
Can somebody tell me what this two lines mean? The whole file is full of this two lines, nothing else.
Thanks so much in advance.It's just logging from the Apache module which handles the protocol between the web server and the servlet container. Chances are your mod_jk configuration has its logging set higher than you want it -- if it is set to "DEBUG", try turning it down (or off, if you desire).
Good luck,
-Derek -
Integrating Apache with Tomcat?
Anyone have a guide to integrating Apache with Tomcat using mod_jk?
I followed some guides online, but they all seem really dated with some obscure references. This seems like it should be on the top of the list....Hi Alan.
I've discovered the exact same problem.... 0.0.0.0 instead of 127.0.0.1
You've obviously not had any replys here, but di you end up working it out on your own? -
Hi, I integrated Apache with Tomcat Cluster on Windows 2000. I instalated mod_jk2.dll, created workers2.properties and configurated server.xml in Tomcat instances. If I try to reach my .jsp file, e.g. http://localhost/root/main.jsp, I get follow message from Tomcat: source root/main.jsp is not available. What�s wrong? Can anybody help me? Apache version: 2.0.47, Tomcat: 1.4.27
Well, the first order of business is to determine exactly where main.jsp is located. If it is at <CATALINA_HOME>/webapps/main.jsp, then it should be at http://localhost:8080/main.jsp. Bypass Apache and verify that you can get to the Tomcat specific pages first.
Basically, we're trying to determine a) the correct URL and b) whether the problem is with Tomcat itself, or with the connections between Apache and Tomcat.
Essentially, we can't tell you where your configuration is incorrect until you tell us what your configuration is. :) -
Steps to configuring log4j with plain text file
can anyone help me with the steps involved with configuring log4j with a plain text configuration file...Where should log4j.properties file be stored?.....do you have a simple example of a config file using a file appender?.....do I have to make changes within the startWebLogic.cmd script?.....Is it possible for you to lay out the procedure for me to begin logging?.....nothing I have tried thus far has worked.....Any help you may be able to provide will be greatly appreciated.
i am using sun jsf implementaion version 1.2
can i know do we need to specify anything for application bean to be called. beacause when i tried to print in sample application also my log was not getting printed.
i have mentioned in my managed bean
<managed-bean>
<managed-bean-name>ApplicationBean1</managed-bean-name>
<managed-bean-class>webapplication3.ApplicationBean1</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
i my page class
protected webapplication3.ApplicationBean1 getApplicationBean1() {
return (webapplication3.ApplicationBean1)getBean("ApplicationBean1");
can i know why it is not getting called.
Maybe you are looking for
-
ALV . How to remove the sort buttons on toolbar in ALV report?
Hi,experts As you know, in default case , the alv report will display two sort buttons(ascending ,descending) on its toolbar , So How to remove the sort buttons on toolbar in ALV report? Thanks for your help .
-
How can One sender communication channel pick two file from two location
Hello I have a requirement that how can One sender communication channel pick two file from two location.Both the file has same name...How to configure the one receiver communication channel.i dont have any IR,no mapping..Please help me...
-
Customizing the Logo for xmlpserver in obiee 11g publisher.
Hi Everyone, Can you guys suggest the steps to change the login logo for Publisher window? as per the oracle documentation I succeeded in Analytics UI customization.But this customization not reflecting in xmlpserver UI. Thanks Arvnd
-
Every morning all sounds on my iPhone 5 are gone/muted
I have noticed that every morning, sometime between 5AM and 7AM, I lose all sounds - ring tone, alerts, even the clickety-clack of the keypad. The sounds are restored only if I power cycle my phone. If someone out there has similar issues and know h
-
Whenever I try to open one of the web pages or JavaScript files I have written, the TextEdit program and every browser will warn me that it was recently downloaded, and is dangerous to open. It wasn't recently downloaded, I edited the document and s