habe ich versucht, das einfache Beispiel von SLF4J FAQ:Warum ist die Ausnahmestapelüberwachung nicht angemeldet?
package com.aed.tests.logging;
import org.slf4j.LoggerFactory;
public class TestLogging
{
public TestLogging()
{
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args)
{
String s = "Hello world";
try
{
Integer i = Integer.valueOf(s);
}
catch(NumberFormatException e)
{
LoggerFactory.getLogger("simplelogger").error("Failed to format {}", s, e);
LoggerFactory.getLogger("simplelogger").error("Without parametrized string", e);
}
}
}
Hier ist der Ausgang:
15:33:51,248000000 [SEVERE]simplelogger: Failed to format Hello world
15:33:51,275000000 [SEVERE]simplelogger: Without parametrized string
I java.util.logging als Logging-Implementierung verwenden, mit den folgenden logging.properties
# Properties file which configures the operation of the JDK
# logging facility.
# The system will look for this config file, first using
# a System property specified at startup:
#
# >java -Djava.util.logging.config.file=myLoggingConfigFilePath
#
# If this property is not specified, then the config file is
# retrieved from its default location at:
#
# JDK_HOME/jre/lib/logging.properties
# Global logging properties.
# ------------------------------------------
# The set of handlers to be loaded upon startup.
# Comma-separated list of class names.
# (? LogManager docs say no comma here, but JDK example has comma.)
handlers=java.util.logging.ConsoleHandler
# Default global logging level.
# Loggers and Handlers may override this level
.level=ALL
# Loggers
# ------------------------------------------
# Loggers are usually attached to packages.
# Here, the level for each package is specified.
# The global level is used by default, so levels
# specified here simply act as an override.
# myapp.ui.level=ALL
# myapp.business.level=CONFIG
# myapp.data.level=SEVERE
# Handlers
# -----------------------------------------
# --- ConsoleHandler ---
# Override of global logging level
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
# HH:MM:ss,nanosec
java.util.logging.SimpleFormatter.format=%1$tT,%1$tN [%4$s]%3$s: %5$s %n
Ich erwartete, das Stacktrace der Ausnahme zu sehen. Fehle ich etwas in der Konfiguration? Soll ich Exception-Strack-Trace irgendwie aktivieren, mit SLF4J oder jdk-Logging?
EDIT Folgen Sie dem "Als doppelt markiert". Meine Frage war nicht, "wie man den Stapel-Trace druckt", aber wie kommt es, am Beispiel von SLF4J, das selbst die Aufgabe ausführt, den Stapel-Trace auszudrucken, hatte ich noch keine Stack-Trace ausgedruckt. Wie gesagt, ich habe den Stack-Trace mit log4j als Implementierung ausgedruckt, aber nicht mit java.util.logging. Es war also eine Frage der falschen Konfiguration von java.util.logging, und ich gab eine Antwort, als ich es herausfand.
Gerade versucht mit log4j wie die Umsetzung, und ich habe den Stapel erhalten Spur. Kann mit der JDK-Protokollierung der Stack-Trace nicht protokolliert werden? – remi