tomcat 日志那点事
tomcat 启动时使用的是java.util.logger 日志框架
tomcat 实现类
下面在启动类中定义了一个log 对象
在main函数中我们打印一个debug日志
该日志是打不出来的
为什么呢?
如何让这该日志打印出来呢?
第一修改tomcat_home/conf/logger.properties 文件日志级别
结果依然没有打印出来
为什么呢?
因此此刻tomcat 并没有启动,默认读的日志文件依然是java_home/jar/lig/logger.properties 文件
修改该文件日志级别后日志打印正常。
细心的朋友们可能会注意到,tomcat为什么会打印红色日志?
因为
System.err 是打印红色字体的
结束...
tomcat 日志从这里开始,欢迎持续关注
跟着疯子从0 学计算机,从这里开始...
https://github.com/sparrowzoo
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
浙公网安备 33010602011771号