• tomcat 日志那点事


    tomcat 启动时使用的是java.util.logger 日志框架

    tomcat 实现类

    package org.apache.juli.logging;
    
    import java.util.logging.ConsoleHandler;
    import java.util.logging.Formatter;
    import java.util.logging.Handler;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    /**
     * Hardcoded java.util.logging commons-logging implementation.
     */
    class DirectJDKLog implements Log {
    
    



    下面在启动类中定义了一个log 对象



    package org.apache.catalina.startup;
    
    import java.io.File;
    import java.io.IOException;
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    import org.apache.catalina.Globals;
    import org.apache.catalina.security.SecurityClassLoad;
    import org.apache.catalina.startup.ClassLoaderFactory.Repository;
    import org.apache.catalina.startup.ClassLoaderFactory.RepositoryType;
    import org.apache.juli.logging.Log;
    import org.apache.juli.logging.LogFactory;
    
    
    /**
     * Bootstrap loader for Catalina.  This application constructs a class loader
     * for use in loading the Catalina internal classes (by accumulating all of the
     * JAR files found in the "server" directory under "catalina.home"), and
     * starts the regular execution of the container.  The purpose of this
     * roundabout approach is to keep the Catalina internal classes (and any
     * other classes they depend on, such as an XML parser) out of the system
     * class path and therefore not visible to application level classes.
     *
     * @author Craig R. McClanahan
     * @author Remy Maucherat
     */
    public final class Bootstrap {
    
        private static final Log log = LogFactory.getLog(Bootstrap.class);
    



    在main函数中我们打印一个debug日志

     /**
         * Main method and entry point when starting Tomcat via the provided
         * scripts.
         *
         * @param args Command line arguments to be processed
         */
        public static void main(String args[]) {
            String javaVersion = System.getProperty("java.version");
            log.debug("starting ..."+javaVersion);
    
    


    该日志是打不出来的
    为什么呢?
    如何让这该日志打印出来呢?
    第一修改tomcat_home/conf/logger.properties 文件日志级别
    结果依然没有打印出来
    为什么呢?
    因此此刻tomcat 并没有启动,默认读的日志文件依然是java_home/jar/lig/logger.properties 文件
    修改该文件日志级别后日志打印正常。

    细心的朋友们可能会注意到,tomcat为什么会打印红色日志?
    因为

       /**
         * Create a ConsoleHandler for System.err.
         * 
         * The ConsoleHandler is configured based on
         * LogManager properties (or their default values).
         *
         */
        public ConsoleHandler() {
            sealed = false;
            configure();
            setOutputStream(System.err);
            sealed = true;
        }
    



    System.err 是打印红色字体的

    结束...

    tomcat 日志从这里开始,欢迎持续关注
    跟着疯子从0 学计算机,从这里开始...
    https://github.com/sparrowzoo
  • 相关阅读:
    【Flink系列十二】使用OpenResty 在InfluxDB协议层拦截Flink指标
    【Azkaban优化】防止IP变化导致频繁登录
    困扰多年的Quartz重复调度的问题,终于找到原因
    【Flink系列十一】FlinkSQL Gateway以及支持Kerberos多租户的实现思路
    【Flink系列十三】FlinkKafkaConnector KafkaSource FlinkKafkaConsumer没有上报指标
    IDEA项目结构出现 0% methods,0% lines covered up
    java去重 up
    svndown下来项目但是导入不了maven包,解决办法 up
    新型病毒加强勒索病毒预防 up
    java list 时间排序, up
  • 原文地址:https://www.cnblogs.com/hiaming/p/8967783.html
Copyright © 2020-2023  润新知