我正在尝试在Tomee应用服务器中打印出DEBUG
级别的日志。
我的logging.properties文件是
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
java.util.logging.SimpleFormatter.format = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$s [location: %2$s] %5$s%6$s%n
1catalina.org.apache.juli.FileHandler.level = FINEST
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.
1catalina.org.apache.juli.FileHandler.formatter = java.util.logging.SimpleFormatter
2localhost.org.apache.juli.FileHandler.level = FINEST
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.
2localhost.org.apache.juli.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = FINEST
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler
com.company.level=FINEST
com.company.handlers=1catalina.org.apache.juli.FileHandler
另外,我在logging.properties
WEB-INF\classes
文件
handlers=1FILE.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
.handlers=java.util.logging.ConsoleHandler
1FILE.org.apache.juli.FileHandler.level=FINEST
1FILE.org.apache.juli.FileHandler.directory=/app-logs
1FILE.org.apache.juli.FileHandler.prefix=file-1
java.util.logging.ConsoleHandler.level=FINEST
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$s [location: %2$s] %5$s%6$s%n
com.company.level=FINEST
com.company.handlers=1FILE.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
并设置JVM PARAMS:
set JAVA_OPTS=%JAVA_OPTS% -Djava.util.logging.config.file="%CATALINA_CONF%\logging.properties"
set JAVA_OPTS=%JAVA_OPTS% -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
我正在尝试在所有日志级别输出应用程序日志:
package com.company.logic.test;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
@Startup
@Singleton
public class TestLoggingImpl implements TestLogging {
private static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, TestLoggingImpl.class);
@Override
@PostConstruct
public void test(){
LOGGER.fatal("TEST_LOGGING: FATAL");
LOGGER.error("TEST_LOGGING: ERROR");
LOGGER.warning("TEST_LOGGING: WARNING");
LOGGER.info("TEST_LOGGING: INFO");
LOGGER.debug("TEST_LOGGING: DEBUG");
LOGGER.log("FINE","TEST_LOGGING: FATAL");
}
}
我在Tomee\logs
目录中获取的日志文件是:
Feb 15, 2017 6:35:25 PM com.company.logic.test.TestLoggingImpl test
SEVERE: TEST_LOGGING: FATAL
Feb 15, 2017 6:35:25 PM com.company.logic.test.TestLoggingImpl test
SEVERE: TEST_LOGGING: ERROR
Feb 15, 2017 6:35:25 PM com.company.logic.test.TestLoggingImpl test
WARNING: TEST_LOGGING: WARNING
Feb 15, 2017 6:35:25 PM com.company.logic.test.TestLoggingImpl test
INFO: TEST_LOGGING: INFO
如果我将.level=FINEST
放在logging.properties中,我会得到tomcat的各种日志,而不是连接到我的应用程序。
有几个问题:
%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$s [location: %2$s] %5$s%6$s%n
)INFO
而非FINEST
file-1
如何解决?
修改
最终,我放弃并为Tomee配置了log4j。
system.properties
openejb.log.factory = log4j
logging.properties
log4j.debug = true
log4j.rootLogger = INFO, CATALINA, CONSOLE
# Define all the appenders
log4j.appender.CATALINA = org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.file = ${catalina.base}/logs/catalina
log4j.appender.CATALINA.append = true
log4j.appender.CATALINA.maxBackupIndex = 10
log4j.appender.CATALINA.encoding = UTF-8
# Roll-over the log once per day
log4j.appender.CATALINA.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
log4j.appender.CATALINA.layout.ConversionPattern = %d %-5p [%t] %c{1} - %m%n
log4j.appender.CATALINA.Threshold = TRACE
log4j.appender.LOCALHOST = org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOCALHOST.file = ${catalina.base}/logs/localhost
log4j.appender.LOCALHOST.append = true
log4j.appender.LOCALHOST.encoding = UTF-8
log4j.appender.LOCALHOST.datepattern = '.'yyyy-MM-dd'.log'
log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
log4j.appender.LOCALHOST.layout.ConversionPattern = %d %-5p [%t] %c{1} - %m%n
log4j.appender.MANAGER = org.apache.log4j.DailyRollingFileAppender
log4j.appender.MANAGER.file = ${catalina.base}/logs/manager
log4j.appender.MANAGER.append = true
log4j.appender.MANAGER.encoding = UTF-8
log4j.appender.MANAGER.datepattern = '.'yyyy-MM-dd'.log'
log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.MANAGER.layout.ConversionPattern = %d %-5p [%t] %c{1} - %m%n
log4j.appender.HOST-MANAGER = org.apache.log4j.DailyRollingFileAppender
log4j.appender.HOST-MANAGER.file = ${catalina.base}/logs/host-manager
log4j.appender.HOST-MANAGER.append = true
log4j.appender.HOST-MANAGER.encoding = UTF-8
log4j.appender.HOST-MANAGER.datepattern = '.'yyyy-MM-dd'.log'
log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d %-5p [%t] %c{1} - %m%n
log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.encoding = UTF-8
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern = %d %-5p [%t] %c{1} - %m%n
log4j.appender.CONSOLE.Threshold = TRACE
# Configure which loggers log to which appenders
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost] = INFO, LOCALHOST, CONSOLE
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] = INFO, MANAGER, CONSOLE
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] = INFO, HOST-MANAGER, CONSOLE
将log4j-1.2.17.jar
置于%TOMEE%\lib
有价值的信息:
尽管设置了DEBUG
log4j.appender.CATALINA.Threshold = TRACE
日志记录级别