1886

Tomcat keeps logging what he wants

Question:

well, I've put this logging.properties configuration file to my web apps src directory:

handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler ############################################################ # Handler specific properties. # Describes specific configuration info for Handlers. ############################################################ org.apache.juli.FileHandler.level = FINE org.apache.juli.FileHandler.directory = ${catalina.base}/logs org.apache.juli.FileHandler.prefix = GenTree. java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

But I can't find anything that I output in the logs except for console and there are no files starting with GenTree* anywhere... Does anybody know anything about this? As much as I understand it's probably using the default settings of my jre that tomcat uses. But I want project specific settings for this project.

I mean how am I supposed to set up the logging? Did I miss anything? There's something about logs in tomcats server.xml, should I modify it? I mean haven't found anything about modifying in server.xml in any article about logging in tomcat. But right now Tomcat does seem to be loggin this pattern which is described in server.xml:

<!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>

Can somebody explain please?

Edit: I've checked the JRE directory (JAVA_HOME) and it doesn't have any logging.properties at all...

Answer1:

You need add the JVM argument if you are using Tomcat from Eclipse to use <a href="http://tomcat.apache.org/tomcat-7.0-doc/logging.html" rel="nofollow">Tomcat JULI</a> on your web application (loggin.properties):

-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager

Open the run configuration of the server, <em>Open lauch configuration</em> <img alt="Tomcat configuration" class="b-lazy" data-src="https://i.stack.imgur.com/Qcxfl.png" data-original="https://i.stack.imgur.com/Qcxfl.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

Add the argument in the VM arguments:

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/Osbc1.png" data-original="https://i.stack.imgur.com/Osbc1.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

See also <a href="https://stackoverflow.com/a/15753752/870248" rel="nofollow"><em>Application specific log in tomcat 7 using JULI</em></a>.

<strong>UPDATE</strong>

I added a clean installation of Tomcat 6.0.36 with Java 7 to eclipse. Next, I created a eclipse project with a listener:

package org.paulvargas.test; import java.io.File; import java.util.logging.Logger; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public final class TestListener implements ServletContextListener { private static final Logger LOG = Logger .getLogger(ServletContextListener.class.getName()); public TestListener() { LOG.info("LOG directory:" + System.getProperty("catalina.base") + File.separator + "logs"); } public void contextInitialized(ServletContextEvent evt) { LOG.info("TestListener initialized: " + evt); } public void contextDestroyed(ServletContextEvent evt) { LOG.info("TestListener destroyed: " + evt); } }

And in the web.xml:

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>TestTomcatJuli</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <listener> <listener-class>org.paulvargas.test.TestListener</listener-class> </listener> </web-app>

I only added to the default JVM parameters the new what I had said, -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager.

-Dcatalina.base="C:\Users\Paul\indigo\.metadata\.plugins\org.eclipse.wst.server.core\tmp0" -Dcatalina.home="D:\Software\apache-tomcat-6.0.36" -Dwtp.deploy="C:\Users\Paul\indigo\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps" -Djava.endorsed.dirs="D:\Software\apache-tomcat-6.0.36\endorsed" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager

The project structure:

C:. | .classpath | .project +---.settings | .jsdtscope | org.eclipse.jdt.core.prefs | org.eclipse.wst.common.component | org.eclipse.wst.common.project.facet.core.xml | org.eclipse.wst.jsdt.ui.superType.container | org.eclipse.wst.jsdt.ui.superType.name +---build | \---classes | | logging.properties | | | \---org | \---paulvargas | \---test | TestListener.class +---src | | logging.properties | | | \---org | \---paulvargas | \---test | TestListener.java \---WebContent +---META-INF | MANIFEST.MF | \---WEB-INF | web.xml | \---lib

The logging.properties is the same of your post.

In the console I see:

may 27, 2013 1:16:09 PM org.paulvargas.test.TestListener <init> INFO: LOG directory:C:\Users\Paul\indigo\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\logs may 27, 2013 1:16:09 PM org.paulvargas.test.TestListener contextInitialized INFO: TestListener initialized: javax.servlet.ServletContextEvent[source=org.apache.catalina.core.ApplicationContextFacade@2f3adb]

And have the file GenTree.2013-05-27.log with the same output.

None other file have been modified, like server.xml, context.xml and without extra libraries.

Recommend

  • There is no Action mapped for namespace / and action name HelloWorld
  • How to disable localhost_access_log files for ColdFusion/Tomcat
  • Migration from Jboss7 to Wildfly: allow access to servlet only from specific IPs
  • Tomcat request logging - how to?
  • Why doesn't CloudFront return the cached version of these identical URL's?
  • Why glBufferSubData need to wait until the VBO is not used by glDrawElements?
  • tap() isn't triggered in RXJS Pipe
  • Dockerfile for tomcat
  • How to check for duplicate entry in DB?
  • \" instead sign of quote (\")
  • App Crashed due to Invalid signature for pointer dequeued from free list in UIImagePickerController
  • How to choose from two connection strings?
  • Determine how much can I write into a filehandle; copying data from one FH to the other
  • Rails is not saving an attribute that is changed [duplicate]
  • Replace Node Name
  • Unable to get CAP_CHOWN and CAP_DAC_OVERRIDE working for regular user
  • How to check if DIV element is disabled using jquery
  • how to remove a div with same ids but display='block' and display='none' in JAVa
  • Boost binary serialization doesn't work occasionally. The parsed data is corrupted sometimes
  • Yii2: Using Kartik Depdrop Widget?
  • getelement by class name for clicking
  • How to add the custom button on google's(device) native application in android?
  • What is the reason that Policy.getPolicy() is considered as it will retain a static reference to the
  • Generic/Unknown HTTP Error with response code 0 using UnityWebRequest
  • Is looping through all style sheets and classes a good idea in JavaScript?
  • Why cout is producing no output on Code Blocks?
  • jquery code not working without breakpoint
  • Defining enums in Cython code that will be used in the C part of code
  • How to display special characters in SQL server 2008?
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • How to make R's read_csv2() recognise the text characters properly
  • Deselecting radio buttons while keeping the View Model in synch
  • Nant, Vault & Windows Integrated Authentication
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • GridView Sorting works once only
  • Circular dependency while pushing http interceptor
  • Linker errors when using intrinsic function via function pointer
  • WPF Applying a trigger on binding failure
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET