我有以下自定义日志记录级别
public class SAMLLoggingLevel extends Level{
public static final String SAMLLOGGING_LEVEL = "SAMLLOGGING";
public static final Level SAML_EXCEPTION_LOGGING = new SAMLLoggingLevel(FATAL_INT + 1, SAMLLOGGING_LEVEL, 7);
public static final Level SAML_DEBUG_LOGGING = new SAMLLoggingLevel(DEBUG_INT+1, SAMLLOGGING_LEVEL, 7);
public static final Level SAML_ERROR_LOGGING = new SAMLLoggingLevel(ERROR_INT+1, SAMLLOGGING_LEVEL, 7);
protected SAMLLoggingLevel(int level, String levelStr, int syslogEquivalent) {
super(level, levelStr, syslogEquivalent);
}
}
我尝试使用以下
进行记录public static Logger logger = Logger.getLogger(xyz.class);
logger.log(SAMLLoggingLevel.SAML_DEBUG_LOGGING, "logger SAML_DEBUG_LOGGING");
logger.log(SAMLLoggingLevel.SAML_ERROR_LOGGING, "logger SAML_ERROR_LOGGING");
logger.log(SAMLLoggingLevel.SAML_EXCEPTION_LOGGING, "logger SAML_EXCEPTION_LOGGING");
我的log4j.properteis文件看起来像这样
log4j.logger.com.xyz=SAML_DEBUG_LOGGING, SAMLLoggingLevel
log4j.appender.SAMLLoggingLevel=org.apache.log4j.RollingFileAppender
log4j.appender.SAMLLoggingLevel.File=/SAML.log
log4j.appender.SAMLLoggingLevel.layout=org.apache.log4j.PatternLayout
log4j.appender.SAMLLoggingLevel.layout.ConversionPattern=%d{MMM dd yyyy HH:mm:ss,SSS zzz} %5p %c{1}:%L - %m%n
我从com.xyz中获取所有类的所有debub消息。我想仅限于使用logger.log(SAMLLoggingLevel ....)
记录的一次答案 0 :(得分:2)
从
更改您的代码log4j.logger.com.xyz=SAML_DEBUG_LOGGING, SAMLLoggingLevel
到
log4j.logger.com.xyz=SAML_DEBUG_LOGGING#com.yourpackagename.SAMLLoggingLevel, SAMLLoggingLevel