Skip to the page
Tecyfy

PySpark interview question · hard

Where can Spark application logs be found?

The short answerIt depends on where Spark runs.

The full answer

It depends on where Spark runs. While the application runs, the Spark UI (port 4040 on the driver) shows jobs and each executor's stdout and stderr. After it finishes, the history server replays the event logs, and the raw logs are with the cluster manager: YARN log aggregation, Kubernetes pod logs, standalone worker directories, or the platform's own log delivery.

Kinds of logs

  • Driver logs: your application's own logging, planning and scheduling messages, and most error messages with stack traces.
  • Executor logs: task errors, out-of-memory errors, garbage collection and Python worker errors.
  • Event logs: a structured record of jobs, stages, tasks and SQL plans, used by the history server to rebuild the UI after the application ends.

While the application is running The Spark UI's Executors tab links to each executor's stdout and stderr.

After it finishes: the history server Enable event logging and point the history server at the same directory:

spark.eventLog.enabled   true
spark.eventLog.dir       hdfs:///spark-logs        # or s3a://bucket/spark-logs
spark.history.fs.logDirectory  hdfs:///spark-logs

The history server (port 18080 by default) shows the same pages as the live UI.

By cluster manager

  • YARN: with log aggregation (yarn.log-aggregation-enable), container logs are copied to HDFS when the application ends; read them with yarn logs -applicationId <application id>. Without it, they stay on each node in the NodeManager's log directory. In client mode the driver's output is on the machine that ran spark-submit.
  • Kubernetes: driver and executors are pods; kubectl logs <driver-pod> while they exist. Executor pods are deleted when the application ends, so ship logs to a central system (such as Fluent Bit to Elasticsearch, Loki or a cloud logging service).
  • Standalone: each worker writes executor logs to its work/<app id>/<executor id>/ directory; the master and worker web UIs link to them.
  • Local mode: everything goes to the console.

Managed platforms

  • Databricks (classic compute): driver logs and the Spark UI in the compute's details, and cluster log delivery to a storage location you configure. On serverless compute the Spark UI and Spark logs aren't available; use the query profile.
  • Amazon EMR: logs archived to S3 when configured, and the persistent Spark history server in the console.
  • Google Dataproc and Azure Synapse/HDInsight: logs in the cloud's logging service and the Spark history server link in the console.

Practical tips

  • Configure logging (Log4j 2 in current Spark) to control levels; spark.sparkContext.setLogLevel("WARN") reduces noise in notebooks.
  • Turn on structured logging (spark.log.structuredLogging.enabled, available since Spark 4) to get JSON logs that can be searched centrally.
  • When a job fails, start from the driver log for the first error, then follow the failed task to its executor log; the real cause (such as an out-of-memory error or a Python traceback) is usually there.

Last updated 16 October 2026