class SparkLogger extends AnyRef
Guidelines for the Structured Logging Framework - Java Logging
Use the org.apache.spark.internal.SparkLoggerFactory
to get the logger instance in Java code:
Getting Logger Instance:
Instead of using org.slf4j.LoggerFactory
, use org.apache.spark.internal.SparkLoggerFactory
to ensure structured logging.
import org.apache.spark.internal.SparkLogger; import org.apache.spark.internal.SparkLoggerFactory; private static final SparkLogger logger = SparkLoggerFactory.getLogger(JavaUtils.class);
Logging Messages with Variables:
When logging messages with variables, wrap all the variables with MDC
s and they will be
automatically added to the Mapped Diagnostic Context (MDC).
import org.apache.spark.internal.LogKeys; import org.apache.spark.internal.MDC; logger.error("Unable to delete file for partition {}", MDC.of(LogKeys.PARTITION_ID$.MODULE$, i));
Constant String Messages: For logging constant string messages, use the standard logging methods.
logger.error("Failed to abort the writer after failing to write map output.", e);
If you want to output logs in java code
through the structured log framework,
you can define custom LogKey
and use it in java
code as follows:
// To add a custom LogKey
, implement LogKey
public static class CUSTOM_LOG_KEY implements LogKey { }
import org.apache.spark.internal.MDC;
logger.error("Unable to delete key {} for cache", MDC.of(CUSTOM_LOG_KEY, "key"));
- Alphabetic
- By Inheritance
- SparkLogger
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
- def debug(msg: String, throwable: Throwable): Unit
- def debug(format: String, arguments: <repeated...>[AnyRef]): Unit
- def debug(format: String, arg1: AnyRef, arg2: AnyRef): Unit
- def debug(format: String, arg: AnyRef): Unit
- def debug(msg: String): Unit
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def error(msg: String, throwable: Throwable, mdcs: <repeated...>[MDC]): Unit
- def error(msg: String, mdcs: <repeated...>[MDC]): Unit
- def error(msg: String, throwable: Throwable): Unit
- def error(msg: String): Unit
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- def getSlf4jLogger(): Logger
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- def info(msg: String, throwable: Throwable, mdcs: <repeated...>[MDC]): Unit
- def info(msg: String, mdcs: <repeated...>[MDC]): Unit
- def info(msg: String, throwable: Throwable): Unit
- def info(msg: String): Unit
- def isDebugEnabled(): Boolean
- def isErrorEnabled(): Boolean
- def isInfoEnabled(): Boolean
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isTraceEnabled(): Boolean
- def isWarnEnabled(): Boolean
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def trace(msg: String, throwable: Throwable): Unit
- def trace(format: String, arguments: <repeated...>[AnyRef]): Unit
- def trace(format: String, arg1: AnyRef, arg2: AnyRef): Unit
- def trace(format: String, arg: AnyRef): Unit
- def trace(msg: String): Unit
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- def warn(msg: String, throwable: Throwable, mdcs: <repeated...>[MDC]): Unit
- def warn(msg: String, mdcs: <repeated...>[MDC]): Unit
- def warn(msg: String, throwable: Throwable): Unit
- def warn(msg: String): Unit
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)