Nomad: Enrich logs with current job status as metadata

Hi,
I wanna enrich each job log with the current job status as metadata. I know that the job status can change through its lifecyle. I thought of assigning an environment variable to a docker label but there is no environment variable that holds the job status. Therefore I think I need another approach to dynamically assign the job status to each job log.

Does anybody can help me and give me tips on how I could manage to achieve that?
In the following my job file:

job "redis" {
  datacenters = ["dc1"]

  type = "service"

  group "cache" {

    task "redis" {
      driver = "docker"

      config {
        image = "redis"
        port_map {
          db = 6379
        }
        labels {
            job_status = "${NOMAD_JOB_STATUS}" # env variable NOMAD_JOB_STATUS does not exist
        }

        logging {
          type = "fluentd"
          config {
            fluentd-address = "localhost:24224"
            tag             = "tag"
            labels          = "job_status"
          }
        }
      }

      resources {
        cpu    = 500 # 500 MHz
        memory = 256 # 256MB
        network {
          mbits = 10
          port "db" {}
        }
      }
  }
}
}

Does anybody have an idea?

I run my modified version of GitHub - attachmentgenie/nomad-logger: Watch Nomad allocations and update logshipper config that can enrich logs for promtail/loki

This looks promising. Could you maybe explain to me how the inner workings look like? How are the logs getting enriched with metadata?

And how could i use the nomad logger to enrich logs with a specific task’s status?