31

I'm trying to set the logging level to DEBUG in an embedded Jetty instance.

The documentation at http://docs.codehaus.org/display/JETTY/Debugging says to -

call SystemProperty.set("DEBUG", "true") before calling new org.mortbay.jetty.Server().

I'm not sure what the SystemProperty class is, it doesn't seem to be documented anywhere. I tried System.setProperty(), but that didn't do the trick.

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
HolySamosa
  • 9,011
  • 14
  • 69
  • 102
  • What version of Jetty? What logging framework(s) do you have on the classpath? – Tim Feb 11 '12 at 00:35
  • I'm using Jetty 7.5.4 at the moment, but can really use any version. For logging, I'm using log4j for my non-Jetty code and just letting SLF4J in JEtty default to the NOP logger implementation (it writes to the debug console, which is all I need). – HolySamosa Feb 13 '12 at 17:51

4 Answers4

27

Add this

-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog 
-Dorg.eclipse.jetty.LEVEL=DEBUG

Snap of Eclipse Configuration

Apurva Singh
  • 4,534
  • 4
  • 33
  • 42
27

My question was answered on the Jetty mailing list by Joakim Erdfelt:

You are looking at the old Jetty 6.x docs at docs.codehaus.org.

DEBUG logging is just a logging level determined by the logging implementation you choose to use.

-D{classref}.LEVEL={level}

Where {classref} is the class reference you want to set the level on, and all sub-class refs. and {level} is one of the values ALL, DEBUG, INFO, WARN

Example: -Dorg.eclipse.jetty.LEVEL=INFO - this will enable INFO level logging for all jetty packages / classes. -Dorg.eclipse.jetty.io.LEVEL=DEBUG - this will enable DEBUG level logging for IO classes only -Dorg.eclipse.jetty.servlet.LEVEL=ALL - this will enable ALL logging (trace events, internally ignored exceptions, etc..) for servlet packages. -Dorg.eclipse.jetty.util.thread.QueuedThreadPool.LEVEL=ALL - this will enable level ALL+ on the specific class only.

HolySamosa
  • 9,011
  • 14
  • 69
  • 102
16

In case you just want to quickly get log messages to stderr add something like this to java command line:

-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -D{classref}.LEVEL=DEBUG
ssasa
  • 1,616
  • 1
  • 18
  • 30
6

You can use this snippet to enable logging:

import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.StdErrLog;
 .
 .
 .
StdErrLog logger = new StdErrLog();
logger.setDebugEnabled(true);
Log.setLog(logger);
Daniel
  • 71
  • 1
  • 1