log4j2 中的标记以这种方式工作:
package org.so.log4j2.test;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
public class Log4j2Test {
public static void main(String[] args)
{
Logger logger = LogManager.getLogger("Test");
Marker LOG4JDBC_OTHER = MarkerManager.getMarker("LOG4JDBC_OTHER");
logger.info("Line to show.");
logger.info(LOG4JDBC_OTHER, "Line to hide");
}
}
使用以下 log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<MarkerFilter marker="LOG4JDBC_OTHER" onMatch="DENY" onMismatch="NEUTRAL"/>
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
<Logger name="Test" level="info" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
</Loggers>
</Configuration>
输出:
12:37:22.416 [main] INFO Test - Line to show.
Logback 中的标记以这种方式工作:
package org.so.logback.test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
public class LogbackTest {
public static void main(String[] args) {
Logger logger = LoggerFactory.getLogger("Test");
Marker LOG4JDBC_OTHER = MarkerFactory.getMarker("LOG4JDBC_OTHER");
logger.info("Line to show");
logger.info(LOG4JDBC_OTHER, "Line to hide");
}
}
有了这个 logback.xml
<?xml version="1.0" ?>
<configuration>
<property name="log.folder" value="./log"/>
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
<Marker>LOG4JDBC_OTHER</Marker>
<OnMatch>DENY</OnMatch>
<OnMismatch>NEUTRAL</OnMismatch>
</turboFilter>
<appender class="ch.qos.logback.core.ConsoleAppender" name="CONSOLE">
<encoder>
<pattern>[%p] [%thread] %logger - %msg%n</pattern>
</encoder>
</appender>
<root>
<level value="INFO"/>
<appender-ref ref="CONSOLE"/>
</root>
<logger name="Test" additivity="false">
<level value="INFO" />
<appender-ref ref="CONSOLE"/>
</logger>
</configuration>
输出:
[INFO] [main] Test - Line to show
希望能帮助到你。
PS也许又是加法标志?