public class LogContext
extends java.lang.Object
Track location in template files during rendering by populating the slf4j MDC tags file
, line
and column
.
An MDC-aware logger can then use this info to display the template location in the message
For instance with webapp-slf4j-logger, it's enough to use %file
, %line
and %column
in the logger format string.
Since this feature can have a performance impact, it has to be enabled in velocity.properties
using:
runtime.log.track_location = true
(typically in a development environment)
Modifier and Type | Class and Description |
---|---|
private static class |
LogContext.StackElement |
Modifier and Type | Field and Description |
---|---|
private static java.lang.ThreadLocal<java.util.Deque<LogContext.StackElement>> |
contextStack |
protected static org.slf4j.Logger |
logger |
static java.lang.String |
MDC_COLUMN |
static java.lang.String |
MDC_FILE |
static java.lang.String |
MDC_LINE |
private static java.lang.String |
STACKTRACE_LINE |
private boolean |
trackLocation |
Constructor and Description |
---|
LogContext(boolean trackLocation) |
Modifier and Type | Method and Description |
---|---|
private void |
clearLogContext() |
java.lang.String[] |
getStackTrace() |
void |
popLogContext() |
void |
pushLogContext(SimpleNode src,
Info info) |
private void |
setLogContext(Info info) |
protected static org.slf4j.Logger logger
public static final java.lang.String MDC_FILE
public static final java.lang.String MDC_LINE
public static final java.lang.String MDC_COLUMN
private boolean trackLocation
private static java.lang.ThreadLocal<java.util.Deque<LogContext.StackElement>> contextStack
private static final java.lang.String STACKTRACE_LINE
public void pushLogContext(SimpleNode src, Info info)
public void popLogContext()
private void setLogContext(Info info)
private void clearLogContext()
public java.lang.String[] getStackTrace()