# Logging

> Logging for Apache Spark applications and the history server, covering the Vector agent the operator adds and forwarding logs to an aggregator.

The Spark operator installs a [vector agent](https://vector.dev/docs/setup/deployment/roles/#agent) as a side-car container in every application Pod except the `job` Pod that runs `spark-submit`. It also configures the logging framework to output logs in XML format. This is the same [format](https://logging.apache.org/log4j/2.x/manual/layouts.html#XMLLayout) used across all Stackable products, and it enables the [vector aggregator](https://vector.dev/docs/setup/deployment/roles/#aggregator) to collect logs across the entire platform.

It is the user’s responsibility to install and configure the vector aggregator, but the agents can discover the aggregator automatically using a discovery ConfigMap as described in the [logging concepts](https://docs.stackable.tech/home/stable/concepts/observability/logging/index.md).

> **Note:** Only logs produced by the application’s driver and executors are collected. Logs produced by `spark-submit` are discarded.

> **Note:** The logs of the [`containerdebug` process](https://docs.stackable.tech/home/stable/concepts/observability/containerdebug/index.md) are collected as well, from the driver and executor Pods and from the history server. They are labelled `container: containerdebug`, although no such Kubernetes container exists. The process runs in the background of the `spark` and `spark-history` containers. It also runs in the `spark-submit` Pod, whose logs are discarded as described above. The label comes from `/stackable/log/containerdebug`, the directory which the operator sets with the `FILE_LOG_DIRECTORY` environment variable and from which the Vector agent derives the container name. Overriding `FILE_LOG_DIRECTORY` with `envOverrides` therefore changes how these logs are aggregated. The agent only collects files one level below `/stackable/log`, so a sibling directory such as `/stackable/log/spark` relabels the events instead of dropping them, while any deeper or shallower path stops the aggregation. A path outside `/stackable/log` also leaves the size-capped log volume.

## History server

The following snippet shows how to configure log aggregation for the history server:

```yaml
apiVersion: spark.stackable.tech/v1alpha1
kind: SparkHistoryServer
metadata:
  name: spark-history
spec:
  vectorAggregatorConfigMapName: spark-vector-aggregator-discovery (1)
  nodes:
    roleGroups:
      default:
        config:
          logging:
            enableVectorAgent: true (2)
            containers:
              spark-history: (3)
                console:
                  level: INFO
                file:
                  level: INFO
                loggers:
                  ROOT:
                    level: INFO
...
```

(1) Name of a ConfigMap that referenced the vector aggregator. See example below.
(2) Enable the vector agent in the history pod.
(3) Configure log levels for file and console outputs.

**Example vector aggregator configuration**

```yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: spark-vector-aggregator-discovery
data:
  ADDRESS: http://spark-vector-aggregator:6123
```
