api 1.7 și slf4j-simplu ca punerea în aplicare. Nu pot't găsi cum să configurați nivelul de logare cu această combinație.
Poate cineva ajuta?
L's, fie prin sistemul de proprietate
-Dorg.slf4j.simpleLogger.defaultLogLevel=debug
sau simplelogger.proprietăți
fișierul pe clase
vezi http://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html pentru detalii
Aceasta este o mostră `simplelogger.proprietățile care vă puteți plasa pe clase (decomentați proprietăți doriți să le utilizați):
# 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
Puteți programatic modifica prin setarea sistemului de proprietate:
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");
}
}
Jurnal de niveluri sunt în EROARE > PREVIN > INFO > DEPANARE > URME.
Vă rugăm să rețineți că, odată ce logger este creat jurnalul nivel poate't fi schimbat. Dacă aveți nevoie pentru a schimba în mod dinamic nivelul de logare s-ar putea doriți să utilizați log4j cu SLF4J.
Am observat că Eemuli spus că poate't a schimba nivelul de jurnal după ce au creat - și în același timp că ar putea fi designul, e't în întregime adevărat.
Am fugit într-o situație în care am fost, folosind o bibliotecă care logat pentru a slf4j - și am fost folosind biblioteca în timp ce scris un maven mojo plugin.
Maven folosește o (tocat) versiune a slf4j SimpleLogger, și am fost în imposibilitatea de a obține plugin-ul meu de cod pentru a redirecționa sale de logare la ceva de genul log4j, pe care am putea controla.
Și nu pot't schimba maven logare config.
Deci, să se liniștească unele zgomotos info mesaje, am descoperit că pot folosi reflecție astfel, să pierd timpul cu SimpleLogger la runtime.
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);
}
Desigur, rețineți, acest lucru nu't un foarte stabil / fiabil soluție... ca se va rupe la următoarea maven oameni își schimbă logger.