API 1.7 및 slf4j-간단한 구현으로. 이 조합으로 로깅 수준을 구성하는 방법을 찾을 수 없습니다.
누구든지 도와줄 수 있나요?
시스템 속성을 통해
-Dorg.slf4j.simpleLogger.defaultLogLevel=debug
또는 클래스 경로의 simplelogger.properties
파일을 통해 설정합니다.
자세한 내용은 http://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html 참조
다음은 클래스 경로에 배치할 수 있는 샘플 simplelogger.properties
입니다(사용하려는 속성의 주석 처리를 해제하세요):
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
#org.slf4j.simpleLogger.defaultLogLevel=info
# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, the default logging detail level is used.
#org.slf4j.simpleLogger.log.xxxxx=
# Set to true if you want the current date and time to be included in output messages.
# Default is false, and will output the number of milliseconds elapsed since startup.
#org.slf4j.simpleLogger.showDateTime=false
# The date and time format to be used in the output messages.
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
# If the format is not specified or is invalid, the default format is used.
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
# Set to true if you want to output the current thread name.
# Defaults to true.
#org.slf4j.simpleLogger.showThreadName=true
# Set to true if you want the Logger instance name to be included in output messages.
# Defaults to true.
#org.slf4j.simpleLogger.showLogName=true
# Set to true if you want the last component of the name to be included in output messages.
# Defaults to false.
#org.slf4j.simpleLogger.showShortLogName=false
시스템 속성을 설정하여 프로그래밍 방식으로 변경할 수 있습니다:
public class App {
public static void main(String[] args) {
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
final org.slf4j.Logger log = LoggerFactory.getLogger(App.class);
log.trace("trace");
log.debug("debug");
log.info("info");
log.warn("warning");
log.error("error");
}
}
로그 수준은 오류, 경고, 정보, 디버그, 추적입니다.
로거가 생성되면 로그 레벨을 변경할 수 없다는 점에 유의하세요. 로깅 수준을 동적으로 변경해야 하는 경우 SLF4J와 함께 log4j을 사용하는 것이 좋습니다.
내가 여기서 I 는 라이브러리를 사용할 수 있는 국면으로 실행했음 로깅된 slf4j - I was a 메이븐 모조 및 라이브러리를 사용하여 쓰는 동안 플러그인에는.
Maven 은 (해킹) 버전의 slf4j 심플러거, 난 내 플러그인에는 log4j 처럼 그 무언가를 로깅하기 가져올 수 없습니다, 어떻게 할 수 있는 코드 경로재정의하기 제어입니다.
따라서 일부 시끄러운 소음을 줄이는 데 사용할 수 있는 정보 메시지, 내가 할 수 있는 한 이 같은 반사 com/downloads/global/corporate/iar/esg_prosupport. 푸츠 심플러거 dell. 런타임용으로 개발하십시오.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.spi.LocationAwareLogger;
try
{
Logger l = LoggerFactory.getLogger("full.classname.of.noisy.logger"); //This is actually a MavenSimpleLogger, but due to various classloader issues, can't work with the directly.
Field f = l.getClass().getSuperclass().getDeclaredField("currentLogLevel");
f.setAccessible(true);
f.set(l, LocationAwareLogger.WARN_INT);
}
catch (Exception e)
{
getLog().warn("Failed to reset the log level of " + loggerName + ", it will continue being noisy.", e);
}
물론, 메모, t # 39 이 isn& 매우 안정적인 / 신뢰할 수 있는 솔루션. 다음 번에 바꾸지 않을 뿐만 아니라 분할합니다 메이븐 여러분 로거에.