tomcat 日志那点事

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

tomcat 实现类

[code]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 {

[/code]


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


[code]
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);
[/code]


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

[code] /**
* 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);

[/code]

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

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

[code] /**
* 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;
}
[/code]


System.err 是打印红色字体的

结束...

tomcat 日志从这里开始,欢迎持续关注
跟着疯子从0 学计算机,从这里开始...
https://github.com/sparrowzoo
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值