Jak skonfigurować slf4j-simple
Api 1.7 i slf4j-proste jak implementacja. Po prostu nie mogę znaleźć, jak skonfigurować poziom logowania za pomocą tej kombinacji.
Czy ktoś może pomóc?
4 answers
To albo przez właściwość systemu
-Dorg.slf4j.simpleLogger.defaultLogLevel=debug
Lub simplelogger.properties
plik na classpath
Zobacz http://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html dla szczegółów
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-22 07:13:49
Jest to próbka simplelogger.properties
, którą możesz umieścić na classpath (odkomentuj właściwości, których chcesz użyć):
# 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
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-10 18:30:44
Można go programowo zmienić ustawiając właściwość systemową:
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");
}
}
Poziomy logów to ERROR > WARN > INFO > DEBUG > TRACE.
Należy pamiętać, że po utworzeniu loggera poziom dziennika nie może zostać zmieniony. Jeśli chcesz dynamicznie zmieniać poziom logowania, możesz użyć log4j z SLF4J.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-18 18:16:50
Zauważyłem, że Eemuli powiedział, że nie można zmienić poziomu dziennika po ich utworzeniu - i chociaż to może być projekt, nie jest to do końca prawda.
Natknąłem się na sytuację, w której używałem biblioteki, która logowała się do slf4j - i używałem biblioteki podczas pisania wtyczki Maven mojo.
Maven używa (zhakowanej) wersji Slf4j SimpleLogger i nie mogłem uzyskać kodu wtyczki, aby przekierować jego logowanie do czegoś takiego jak log4j, który mogłem kontrolować.
I Ja nie można zmienić konfiguracji logowania maven.
Więc, aby wyciszyć kilka hałaśliwych wiadomości informacyjnych, odkryłem, że mogę użyć refleksji w taki sposób, aby futz z SimpleLogger w czasie wykonywania.
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);
}
Oczywiście, zauważ, że nie jest to bardzo stabilne / niezawodne rozwiązanie... jak to się zepsuje następnym razem, gdy ludzie z maven zmienią logger.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-06 15:09:46