github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/logs.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: logs Stanza - Job Specification
     4  description: |-
     5    The "logs" stanza configures the log rotation policy for a task's stdout and
     6    stderr. Logging is enabled by default with sane defaults. The "logs" stanza
     7    allows for finer-grained control over how Nomad handles log files.
     8  ---
     9  
    10  # `logs` Stanza
    11  
    12  <Placement groups={['job', 'group', 'task', 'logs']} />
    13  
    14  The `logs` stanza configures the log rotation policy for a task's `stdout` and
    15  `stderr`. Logging is enabled by default with sane defaults (provided in the
    16  parameters section below), and there is currently no way to disable logging for
    17  tasks. The `logs` stanza allows for finer-grained control over how Nomad handles
    18  log files.
    19  
    20  Nomad's log rotation works by writing stdout/stderr output from tasks to a file
    21  inside the `alloc/logs/` directory with the following format:
    22  `<task-name>.<stdout/stderr>.<index>`. Output is written to a particular index,
    23  starting at zero, till that log file hits the configured `max_file_size`. After,
    24  a new file is created at `index + 1` and logs will then be written there. A log
    25  file is never rolled over, instead Nomad will keep up to `max_files` worth of
    26  logs and once that is exceeded, the log file with the lowest index is deleted.
    27  
    28  ```hcl
    29  job "docs" {
    30    group "example" {
    31      task "server" {
    32        logs {
    33          max_files     = 10
    34          max_file_size = 10
    35        }
    36      }
    37    }
    38  }
    39  ```
    40  
    41  For information on how to interact with logs after they have been configured,
    42  please see the [`nomad alloc logs`][logs-command] command.
    43  
    44  ## `logs` Parameters
    45  
    46  - `max_files` `(int: 10)` - Specifies the maximum number of rotated files Nomad
    47    will retain for `stdout` and `stderr`. Each stream is tracked individually, so
    48    specifying a value of 2 will create 4 files - 2 for stdout and 2 for stderr
    49  
    50  - `max_file_size` `(int: 10)` - Specifies the maximum size of each rotated file
    51    in `MB`. If the amount of disk resource requested for the task is less than
    52    the total amount of disk space needed to retain the rotated set of files,
    53    Nomad will return a validation error when a job is submitted.
    54  
    55  ## `logs` Examples
    56  
    57  The following examples only show the `logs` stanzas. Remember that the
    58  `logs` stanza is only valid in the placements listed above.
    59  
    60  ### Configure Defaults
    61  
    62  This example shows a default logging configuration. Yes, it is empty on purpose.
    63  Nomad automatically enables logging with sane defaults as described in the
    64  parameters section above.
    65  
    66  ```hcl
    67  
    68  ```
    69  
    70  ### Customization
    71  
    72  This example asks Nomad to retain 3 rotated files for each of `stderr` and
    73  `stdout`, each a maximum size of 5 MB per file. The minimum disk space this
    74  would require is 30 MB (3 `stderr` &plus; 3 `stdout` &times; 5 MB &equals; 30 MB).
    75  
    76  ```hcl
    77  logs {
    78    max_files     = 3
    79    max_file_size = 5
    80  }
    81  ```
    82  
    83  [logs-command]: /docs/commands/alloc/logs 'Nomad logs command'