惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
有赞技术团队
有赞技术团队
博客园 - 司徒正美
量子位
N
News and Events Feed by Topic
T
Threatpost
Last Week in AI
Last Week in AI
D
Darknet – Hacking Tools, Hacker News & Cyber Security
酷 壳 – CoolShell
酷 壳 – CoolShell
C
CERT Recently Published Vulnerability Notes
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
Intezer
人人都是产品经理
人人都是产品经理
T
Tenable Blog
IT之家
IT之家
雷峰网
雷峰网
腾讯CDC
博客园 - 聂微东
V
Visual Studio Blog
S
SegmentFault 最新的问题
Scott Helme
Scott Helme
Spread Privacy
Spread Privacy
月光博客
月光博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
罗磊的独立博客
N
Netflix TechBlog - Medium
J
Java Code Geeks
宝玉的分享
宝玉的分享
F
Full Disclosure
WordPress大学
WordPress大学
A
Arctic Wolf
小众软件
小众软件
AWS News Blog
AWS News Blog
Attack and Defense Labs
Attack and Defense Labs
NISL@THU
NISL@THU
AI
AI
Hugging Face - Blog
Hugging Face - Blog
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
N
News | PayPal Newsroom
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org

博客园 - hiaming

doclever 5.5.1 安装及升级【原创】 SPARROW-JS 从0开始写 0依赖,原生JS框架 Sparrow算法篇 从日期取交集到思维模式-2 高性能轻量级markdown 解析器java 版sparrow-markdown Sparrow 算法篇 由日期取交集到思维模式 自己动手写mvc框架SPARROW MVC REDIS客户端封装实践2 SPARROW 框架redis客户端封装实践 SPARROW架构介绍 Sparrow 框架设计哲学 陌院俅颗难炎先当粮澜 openresty在centos/redhat6.7上部署 Redhat6.7 切换Centos yum源 Quartz corn时间表达式(转) Jquery控制滚动Div 滚动条事件 fastjson排序 Map多层嵌套转换自动排序问题终极解决方案 Spring 外部注入Bean (JAX-WS) SSH,如何恢复通过输入密码的方式来登录服务器 Redhat Linux6.5 开启VNC 远程桌面
tomcat 日志那点事
hiaming · 2017-07-15 · via 博客园 - hiaming

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