tomcat 日志 java.util.logging.Logger使用 (二)
来源:互联网 发布:android sdk for mac 编辑:程序博客网 时间:2024/05/05 02:00
# default file output is in user's home directory. java.util.logging.FileHandler.pattern = %h/java%u.log java.util.logging.FileHandler.limit = 50000 java.util.logging.FileHandler.count = 1 java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter # Limit the message that are printed on the console to INFO and above. java.util.logging.ConsoleHandler.level = WARNING java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
1:重写输出的日志的格式
需要配置一下java.util.logging.ConsoleHanlder.formatter 属性。
这个问题在java SE程序中没问题。 java程序可以通过该配置找到自定义的Formatter
但是放到Tomcat等web工程里。问题就出现了
且看ConsoleHandler的源码
public class ConsoleHandler extends StreamHandler { // Private method to configure a ConsoleHandler from LogManager // properties and/or default values as specified in the class // javadoc. private void configure() { LogManager manager = LogManager.getLogManager();String cname = getClass().getName();setLevel(manager.getLevelProperty(cname +".level", Level.INFO));setFilter(manager.getFilterProperty(cname +".filter", null));setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter()));try { setEncoding(manager.getStringProperty(cname +".encoding", null));} catch (Exception ex) { try { setEncoding(null); } catch (Exception ex2) {// doing a setEncoding with null should always work.// assert false; }} }其中有一行代码:这里用于设置配置文件里置顶的.formatter
setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter()));跟踪进去发现:ClassLoader.getSystemClassLoader 根本无法反射到指定的class
Formatter getFormatterProperty(String name, Formatter defaultValue) {String val = getProperty(name);try { if (val != null) {Class clz = ClassLoader.getSystemClassLoader().loadClass(val); return (Formatter) clz.newInstance(); }} catch (Exception ex) { // We got one of a variety of exceptions in creating the // class or creating an instance. // Drop through.}
继续查阅Tomcat的相关文档
http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
System — This class loader is normally initialized from the contents of the CLASSPATH environment variable. All such classes are visible to both Tomcat internal classes, and to web applications. However, the standard Tomcat startup scripts ($CATALINA_HOME/bin/catalina.sh or %CATALINA_HOME%\bin\catalina.bat) totally ignore the contents of the CLASSPATH environment variable itself, and instead build the System class loader from the following repositories:$CATALINA_HOME/bin/bootstrap.jar — Contains the main() method that is used to initialize the Tomcat server, and the class loader implementation classes it depends on.$CATALINA_BASE/bin/tomcat-juli.jar or $CATALINA_HOME/bin/tomcat-juli.jar — Logging implementation classes. These include enhancement classes to java.util.logging API, known as Tomcat JULI, and a package-renamed copy of Apache Commons Logging library used internally by Tomcat. See logging documentation for more details.If tomcat-juli.jar is present in $CATALINA_BASE/bin, it is used instead of the one in $CATALINA_HOME/bin. It is useful in certain logging configurations$CATALINA_HOME/bin/commons-daemon.jar — The classes from Apache Commons Daemon project. This JAR file is not present in the CLASSPATH built by catalina.bat|.sh scripts, but is referenced from the manifest file of bootstrap.jar.
发现SystemClassLoader只能加载 Tomcat-7.0.34\bin 目录下的三个Jar 。
也就是说如果需要继续使用JDK自带的log 则没办法重写Formater等。。。
- tomcat 日志 java.util.logging.Logger使用 (二)
- tomcat 日志 java.util.logging.Logger使用 (一)
- tomcat 日志 java.util.logging.Logger使用 (三)
- tomcat 日志 java.util.logging.Logger使用 (四)
- tomcat 日志 java.util.logging.Logger使用 (五)
- 【java日志】java.util.logging.Logger使用详解
- 如何使用java.util.logging中的Logger来记录日志
- java日志 java.util.logging.Logger用法
- (个人笔记) java.util.logging.Logger 写日志
- 利用java.util.logging.Logger输出日志
- java.util.logging.Logger
- java.util.logging.Logger
- java.util.logging.Logger
- java.util.logging.Logger
- java.util.logging.Logger
- java.util.logging.Logger使用详解
- java.util.logging.Logger使用详解
- java.util.logging.Logger 使用详解
- javascript顶层页面的parent是自己
- 软件SKIN技术
- SQL 中NULL的运算
- Field, Property, Attribute
- win7下破解qtp10
- tomcat 日志 java.util.logging.Logger使用 (二)
- 【CSDN2012年度博客之星】需要您的一票,感谢大家的支持
- Eclipse “cannot be resolved to a type” error
- java正则表达式学习总结,以及和javascript正则表达式的区别
- 系统思考是种能力--读《第五项修炼》有感
- Java环境变量的配置
- Dublin Core
- SQL中合并多行记录的方法总汇
- s5pv210 android 4.0.4 设置固定ip移植