• 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
  • 相关阅读:
    3513: [MUTC2013]idiots
    ELK+Filebeat+Kafka+ZooKeeper 构建海量日志分析平台(elk5.2+filebeat2.11)
    【python全栈开发】初识python
    SQL疑难问题
    费用分摊问题
    透过现象看本质
    关于python3round与float的四省五入精度的问题
    Win10下VSCode安装PlantUML
    安装pymssql
    ensorFlow的安装
  • 原文地址:https://www.cnblogs.com/hiaming/p/8967783.html
Copyright © 2020-2023  润新知