- 浏览: 76378 次
- 性别:
- 来自: 广州
文章分类
最新评论
Tomcat6源码分析(Logger)
public interface Log { // ----------------------------------------------------- Logging Properties /** * <p> Is debug logging currently enabled? </p> * * <p> Call this method to prevent having to perform expensive operations * (for example, <code>String</code> concatenation) * when the log level is more than debug. </p> */ public boolean isDebugEnabled(); /** * <p> Is error logging currently enabled? </p> * * <p> Call this method to prevent having to perform expensive operations * (for example, <code>String</code> concatenation) * when the log level is more than error. </p> */ public boolean isErrorEnabled(); /** * <p> Is fatal logging currently enabled? </p> * * <p> Call this method to prevent having to perform expensive operations * (for example, <code>String</code> concatenation) * when the log level is more than fatal. </p> */ public boolean isFatalEnabled(); /** * <p> Is info logging currently enabled? </p> * * <p> Call this method to prevent having to perform expensive operations * (for example, <code>String</code> concatenation) * when the log level is more than info. </p> */ public boolean isInfoEnabled(); /** * <p> Is trace logging currently enabled? </p> * * <p> Call this method to prevent having to perform expensive operations * (for example, <code>String</code> concatenation) * when the log level is more than trace. </p> */ public boolean isTraceEnabled(); /** * <p> Is warn logging currently enabled? </p> * * <p> Call this method to prevent having to perform expensive operations * (for example, <code>String</code> concatenation) * when the log level is more than warn. </p> */ public boolean isWarnEnabled(); // -------------------------------------------------------- Logging Methods /** * <p> Log a message with trace log level. </p> * * @param message log this message */ public void trace(Object message); /** * <p> Log an error with trace log level. </p> * * @param message log this message * @param t log this cause */ public void trace(Object message, Throwable t); /** * <p> Log a message with debug log level. </p> * * @param message log this message */ public void debug(Object message); /** * <p> Log an error with debug log level. </p> * * @param message log this message * @param t log this cause */ public void debug(Object message, Throwable t); /** * <p> Log a message with info log level. </p> * * @param message log this message */ public void info(Object message); /** * <p> Log an error with info log level. </p> * * @param message log this message * @param t log this cause */ public void info(Object message, Throwable t); /** * <p> Log a message with warn log level. </p> * * @param message log this message */ public void warn(Object message); /** * <p> Log an error with warn log level. </p> * * @param message log this message * @param t log this cause */ public void warn(Object message, Throwable t); /** * <p> Log a message with error log level. </p> * * @param message log this message */ public void error(Object message); /** * <p> Log an error with error log level. </p> * * @param message log this message * @param t log this cause */ public void error(Object message, Throwable t); /** * <p> Log a message with fatal log level. </p> * * @param message log this message */ public void fatal(Object message); /** * <p> Log an error with fatal log level. </p> * * @param message log this message * @param t log this cause */ public void fatal(Object message, Throwable t);
这个接口在tomcat6中只有一个jdk默认的实现,org.apache.juli.logging.DirectJDKLog,
class DirectJDKLog implements Log { // no reason to hide this - but good reasons to not hide public Logger logger; /** Alternate config reader and console format */ private static final String SIMPLE_FMT="org.apache.tomcat.util.log.JdkLoggerFormatter"; private static final String SIMPLE_CFG="org.apache.tomcat.util.log.JdkLoggerConfig"; static { if( System.getProperty("java.util.logging.config.class") ==null && System.getProperty("java.util.logging.config.file") ==null ) { // default configuration - it sucks. Let's override at least the // formatter for the console try { Class.forName(SIMPLE_CFG).newInstance(); } catch( Throwable t ) { } try { Formatter fmt=(Formatter)Class.forName(SIMPLE_FMT).newInstance(); // it is also possible that the user modifed jre/lib/logging.properties - // but that's really stupid in most cases Logger root=Logger.getLogger(""); Handler handlers[]=root.getHandlers(); for( int i=0; i< handlers.length; i++ ) { // I only care about console - that's what's used in default config anyway if( handlers[i] instanceof ConsoleHandler ) { handlers[i].setFormatter(fmt); } } } catch( Throwable t ) { // maybe it wasn't included - the ugly default will be used. } } } public DirectJDKLog(String name ) { logger=Logger.getLogger(name); } public final boolean isErrorEnabled() { return logger.isLoggable(Level.SEVERE); } public final boolean isWarnEnabled() { return logger.isLoggable(Level.WARNING); } public final boolean isInfoEnabled() { return logger.isLoggable(Level.INFO); } public final boolean isDebugEnabled() { return logger.isLoggable(Level.FINE); } public final boolean isFatalEnabled() { return logger.isLoggable(Level.SEVERE); } public final boolean isTraceEnabled() { return logger.isLoggable(Level.FINER); } public final void debug(Object message) { log(Level.FINE, String.valueOf(message), null); } public final void debug(Object message, Throwable t) { log(Level.FINE, String.valueOf(message), t); } public final void trace(Object message) { log(Level.FINER, String.valueOf(message), null); } public final void trace(Object message, Throwable t) { log(Level.FINER, String.valueOf(message), t); } public final void info(Object message) { log(Level.INFO, String.valueOf(message), null); } public final void info(Object message, Throwable t) { log(Level.INFO, String.valueOf(message), t); } public final void warn(Object message) { log(Level.WARNING, String.valueOf(message), null); } public final void warn(Object message, Throwable t) { log(Level.WARNING, String.valueOf(message), t); } public final void error(Object message) { log(Level.SEVERE, String.valueOf(message), null); } public final void error(Object message, Throwable t) { log(Level.SEVERE, String.valueOf(message), t); } public final void fatal(Object message) { log(Level.SEVERE, String.valueOf(message), null); } public final void fatal(Object message, Throwable t) { log(Level.SEVERE, String.valueOf(message), t); } // from commons logging. This would be my number one reason why java.util.logging // is bad - design by comitee can be really bad ! The impact on performance of // using java.util.logging - and the ugliness if you need to wrap it - is far // worse than the unfriendly and uncommon default format for logs. private void log( Level level, String msg, Throwable ex ) { if (logger.isLoggable(level)) { // Hack (?) to get the stack trace. Throwable dummyException=new Throwable(); StackTraceElement locations[]=dummyException.getStackTrace(); // Caller will be the third element String cname="unknown"; String method="unknown"; if( locations!=null && locations.length >2 ) { StackTraceElement caller=locations[2]; cname=caller.getClassName(); method=caller.getMethodName(); } if( ex==null ) { logger.logp( level, cname, method, msg ); } else { logger.logp( level, cname, method, msg, ex ); } } } // for LogFactory static void release() { } static Log getInstance(String name) { return new DirectJDKLog( name ); } }
这是log的uml
要实现自己Log其实很简单,只要你的logger要有一个名为name的构造函数。
相关推荐
源码分析可以帮助开发者理解这些特性的实现细节,以及Tomcat如何优化性能和保证稳定性。 在【压缩包子文件的文件名称列表】中,"tomcat-source-maven-master"可能是一个包含Tomcat源码的Maven项目。Maven是一个流行...
### TOMCAT源码分析——启动框架详解 #### 一、前言 TOMCAT作为一款广泛使用的开源Java Servlet容器,其内部实现复杂且强大。本文旨在深入剖析TOMCAT的启动框架及其整体架构,帮助读者更好地理解其工作原理。...
【Tomcat源码分析】 Tomcat作为一款广泛应用的开源Java Servlet容器,它的源码解析对于深入理解Web服务器的工作原理和优化应用性能至关重要。本文将主要探讨Tomcat的启动框架、核心组件及其相互关系。 首先,...
6. **监控和分析**:使用Log4j的特性,可以方便地对日志进行归档、分割、过滤,甚至可以结合ELK(Elasticsearch, Logstash, Kibana)或Graylog等工具进行实时日志分析。 通过以上步骤,你可以实现更灵活的日志管理...
标题中的“在Tomcat的访问日志配置:awstats”涉及到的是Apache Tomcat服务器的访问日志管理和分析工具——AWStats。AWStats是一款开源的Web服务器统计分析软件,它可以实时或者定期分析服务器的访问日志,提供详细...
Servlet源码的分析能帮助我们深入理解HTTP请求处理流程、服务器生命周期管理以及Java Web开发的底层机制。Apache Tomcat是一款广泛应用的Servlet容器,它实现了Java Servlet和JavaServer Pages(JSP)规范。在这里,...
Log4j相比Juli,提供了更丰富的日志级别、布局和输出策略,使得日志管理和分析更加便捷。 **三、配置步骤** 1. **下载Log4j**:首先,你需要从Apache官方网站下载Log4j的最新版本,并将其解压到你的项目或Tomcat的...
为了充分利用这套源码,我们需要具备一定的IT技术背景,特别是对Java和Web服务器如Tomcat的熟悉程度。 首先,为了部署和运行包含此源码的Web应用程序,我们需要准备以下软件环境: 1. **下载并安装Eclipse**:...
对于初学者来说,Tomcat的源码可能较为庞大,但对于进阶学习者,它是深入理解Servlet和JSP工作原理的好资源。除此之外,还有Jetty、Jigsaw和Jo!等更小型的Servlet容器可供选择。 在JDBC方向,作者提到了Hypersonic ...
11.6.6 启动Tomcat运行示例 11.4 整合Spring和Struts 11.4.1 Spring和Struts的整合方式 11.4.2 编写实现登录的页面regedit.jsp 11.4.3 编写存储登录用户信息的类User.java 11.4.4 编写控制器RegeditAction.java ...
Java开发的简单WEB服务器...通过分析和实践这个简单的Java Web服务器源码,你可以深入理解网络编程的基本概念,以及如何用Java实现一个基本的Web服务器。这将对进一步学习Spring Boot、Tomcat等高级Web框架大有裨益。
一共四个,其中pdf 三个包,源码一个包 第一章 J2EE快速入门 1.1 J2EE概述 1.1.1 J2EE的来源 1.1.2 J2EE整体框架 1.1.3 从J2EE到JavaEE 1.2 J2EE组件 1.2.1 客户端组件 1.2.2 Web组件 1.2.3 业务逻辑组件 1.3 J2EE...
一共四个,其中pdf 三个包,源码一个包 第一章 J2EE快速入门 1.1 J2EE概述 1.1.1 J2EE的来源 1.1.2 J2EE整体框架 1.1.3 从J2EE到JavaEE 1.2 J2EE组件 1.2.1 客户端组件 1.2.2 Web组件 1.2.3 业务逻辑组件 1.3 J2EE...
一共四个,其中pdf 三个包,源码一个包 第一章 J2EE快速入门 1.1 J2EE概述 1.1.1 J2EE的来源 1.1.2 J2EE整体框架 1.1.3 从J2EE到JavaEE 1.2 J2EE组件 1.2.1 客户端组件 1.2.2 Web组件 1.2.3 业务逻辑组件 1.3 J2EE...
总之,"严重: Error listenerStart" 错误提示需要我们深入源码,检查日志配置,分析可能的依赖冲突,以及对监听器代码进行调试,以找到并解决问题。在这个过程中,熟悉Java Web应用的生命周期、日志框架的工作原理...
它是由Apache软件基金会开发的,被广泛应用于大数据生态系统中,尤其是与Hadoop结合使用时,能够有效地将分布式系统的日志数据流式传输到存储或分析系统。Flume的设计理念是简单、可靠和可扩展,其核心特性包括容错...