Tomcat记录他想要的东西 [英] Tomcat keeps logging what he wants

查看:141
本文介绍了Tomcat记录他想要的东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很好,我把这个logging.properties配置文件到我的web应用程序src目录:

  handlers = org。 apache.juli.FileHandler,java.util.logging.ConsoleHandler 

############################# ##############################
#Handler的特定属性。
#描述处理程序的特定配置信息。
############################################## ##############

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

但是我在日志中找不到任何输出,除了控制台,没有任何文件从GenTree *开始...
有没有人知道这个?据我所知,它可能使用tomcat使用的我的jre的默认设置。但我想要这个项目的项目具体设置。



我的意思是我应该如何设置日志记录?我错过了什么吗?有关于tomcats server.xml中的日志的内容,我应该修改吗?我的意思是没有找到任何关于在server.xml中修改任何文章关于登录tomcat。但现在Tomcat似乎是在server.xml中描述的这种模式:

 <! - 访问日志处理所有示例。 
文档:/docs/config/valve.html
注意:使用的模式等效于使用pattern =common - >
< Valve className =org.apache.catalina.valves.AccessLogValvedirectory =logspattern =%h%l%u%t& quot;%r&%s%b prefix =localhost_access_log。 suffix =。txt/>

有人可以解释吗?



:我检查了JRE目录(JAVA_HOME),它根本没有任何logging.properties ...

解决方案

如果您使用Eclipse中的Tomcat来使用 Tomcat JULI,则需要添加JVM参数 loggin.properties ):

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

打开运行配置



在VM参数中添加参数:





另请参阅 UPDATE

$ b>


$ b

我添加了一个干净的安装的Tomcat 6.0.36与Java 7到eclipse。接下来,我使用监听器创建了一个eclipse项目:

  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);
}

}

 <?xml version =1.0encoding =UTF-8?& 
< web-app xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexmlns =http://java.sun.com/xml/ns/javaeexmlns :web =http://java.sun.com/xml/ns/javaee/web-app_2_5.xsdxsi:schemaLocation =http://java.sun.com/xml/ns/javaee http:// java.sun.com/xml/ns/javaee/web-app_2_5.xsdid =WebApp_IDversion =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>

我只是添加到默认的JVM参数新的我说的话, -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\-Djava.util.logging.manager = org.apache.juli.ClassLoaderLogManager 

项目结构:

  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

logging.properties与您的帖子相同。



在控制台中,我看到:

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

并拥有文件 GenTree.2013-05-27.log



没有其他文件被修改,例如 server.xml context.xml ,而没有额外的库。


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...

解决方案

You need add the JVM argument if you are using Tomcat from Eclipse to use Tomcat JULI on your web application (loggin.properties):

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

Open the run configuration of the server, Open lauch configuration

Add the argument in the VM arguments:

See also Application specific log in tomcat 7 using JULI.

UPDATE

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.

这篇关于Tomcat记录他想要的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆