package internal
Type Members
- trait LogKeyShims extends LogKey
All structured logging
keysused inMDCmust be extendsLogKeyAll structured logging
keysused inMDCmust be extendsLogKeyLogKeys serve as identifiers for mapped diagnostic contexts (MDC) within logs. Follow these guidelines when adding a new LogKey:- Define all structured logging keys in
DeltaLogKeys.scala, and sort them alphabetically for ease of search.- Use
UPPER_SNAKE_CASEfor key names.- Key names should be both simple and broad, yet include specific identifiers like
STAGE_ID,TASK_ID, andJOB_IDwhen needed for clarity. For instance, useMAX_ATTEMPTSas a general key instead of creating separate keys for each scenario such asEXECUTOR_STATE_SYNC_MAX_ATTEMPTSandMAX_TASK_FAILURES. This balances simplicity with the detail needed for effective logging.- Use abbreviations in names if they are widely understood, such as
APP_IDfor APPLICATION_ID, andK8Sfor KUBERNETES.- For time-related keys, use milliseconds as the unit of time.
- trait LoggingShims extends Logging
Guidelines for the Structured Logging Framework - Scala Logging
Guidelines for the Structured Logging Framework - Scala Logging
Use the
org.apache.spark.internal.Loggingtrait for logging in Scala code: Logging Messages with Variables: When logging a message with variables, wrap all the variables withMDCs and they will be automatically added to the Mapped Diagnostic Context (MDC). This allows for structured logging and better log analysis.logInfo(log"Trying to recover app: ${MDC(DeltaLogKeys.APP_ID, app.id)}")
Constant String Messages: If you are logging a constant string message, use the log methods that accept a constant string.
logInfo("StateStore stopped")
Exceptions: To ensure logs are compatible with Spark SQL and log analysis tools, avoid
Exception.printStackTrace(). UselogError,logWarning, andlogInfomethods from theLoggingtrait to log exceptions, maintaining structured and parsable logs.If you want to output logs in
scala codethrough the structured log framework, you can definecustom LogKeyand use it inscalacode as follows:// To add a
custom LogKey, implementLogKeycase object CUSTOM_LOG_KEY extends LogKey import org.apache.spark.internal.MDC; logInfo(log"${MDC(CUSTOM_LOG_KEY, "key")}")