java 使用 JULI 登录 tomcat 7 的特定应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15750564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Application specific log in tomcat 7 using JULI?
提问by user364902
I'm using java system logging in tomcat 7, but no logging statements get written to the log. I've added this file to my WEB-INF/classes. The log file "new-xyz-test" gets created (so I have at least some of the config right) but its empty - no log statements get printed to it.
我正在使用 java 系统登录 tomcat 7,但没有将日志语句写入日志。我已将此文件添加到我的 WEB-INF/classes.xml 文件中。日志文件“new-xyz-test”被创建(所以我至少有一些配置正确)但它是空的 - 没有日志语句被打印到它。
handlers=java.util.logging.ConsoleHandler, org.apache.juli.FileHandler
org.apache.juli.FileHandler.level=ALL
org.apache.juli.FileHandler.directory=${catalina.base}/logs
org.apache.juli.FileHandler.prefix=new-xyz-test-
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
com.xyz.level=ALL
com.xyz.handlers=org.apache.juli.FileHandler
回答by Paul Vargas
To configure JULI in the web applications you need have a logging.properties
file in the WEB-INF/classes
directory. If you use the default handlers, you may lose messages. You need to specify a prefix for the handler in your file.
要在 Web 应用程序中配置 JULI,您需要logging.properties
在WEB-INF/classes
目录中有一个文件。如果您使用默认处理程序,您可能会丢失消息。您需要为文件中的处理程序指定前缀。
handlers=1FILE.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
.handlers=java.util.logging.ConsoleHandler
1FILE.org.apache.juli.FileHandler.level=FINEST
1FILE.org.apache.juli.FileHandler.directory=/app-logs
1FILE.org.apache.juli.FileHandler.prefix=file-1
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
com.xyz.level=INFO
com.xyz.handlers=1FILE.org.apache.juli.FileHandler
com.abc.level=INFO
com.abc.handlers=java.util.logging.ConsoleHandler
A
handler prefix (e.g. 1FILE.
) starts with a number, then has an arbitrary string, and ends with a period (.).
处理程序前缀(例如1FILE.
)以数字开头,然后是任意字符串,并以句点 (.) 结尾。
- See more in Logging in Tomcat
- 在 Tomcat 中查看更多信息
Arguments in the JVM
JVM 中的参数
If you are not running the Tomcat from the startup.sh
or startup.bat
, you need to specify:
如果您不是从startup.sh
或运行 Tomcat,则startup.bat
需要指定:
- The location of the general
logging.properties
for Tomcat (in theconf
directory of Tomcat) - The manager
org.apache.juli.ClassLoaderLogManager
. This is important because allows you to configure for each web application different loggin options. By default, a JVM process can only have a single configuration file.) ,
- 一般
logging.properties
为Tomcat的位置(在conf
Tomcat目录下) - 经理
org.apache.juli.ClassLoaderLogManager
。这很重要,因为允许您为每个 Web 应用程序配置不同的登录选项。默认情况下,一个 JVM 进程只能有一个配置文件。),
Similar to the next (I'm using eclipse):
类似于下一个(我正在使用 eclipse):
-Djava.util.logging.config.file="C:\Users\Paul\workspaces\utils\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
By default, java.util.logging
read the file that is included in the JDK or JRE, e.g.:
默认情况下,java.util.logging
读取 JDK 或 JRE 中包含的文件,例如:
"C:\Software\jdk1.7.0_17\jre\lib\logging.properties"
- Setting Tomcat Heap Size (JVM Heap) in Eclipse, for how to add arguments in the VM
- 在 Eclipse 中设置 Tomcat Heap Size (JVM Heap),了解如何在 VM 中添加参数
回答by Doron
are you sure that you write to the correct logger , i.e. Logger.getLogger("com.xyz")
?
你确定你写的是正确的记录器,即Logger.getLogger("com.xyz")
?
I think that you may got wrong when you wrote in logging.properties:com.xyz.level=ALL com.xyz.handlers=org.apache.juli.FileHandler
in the case that you actually write to the logger Logger.getLogger(com.xyz.YourClass.class)
, that because in the logging properties file you should write the logger name which is in your case com.xyz.YourClass
我认为您在 logging.propertiescom.xyz.level=ALL com.xyz.handlers=org.apache.juli.FileHandler
中写入时可能会出错:在您实际写入 logger 的情况下Logger.getLogger(com.xyz.YourClass.class)
,因为在日志记录属性文件中,您应该写入符合您情况的记录器名称com.xyz.YourClass