github.com/smintz/nomad@v0.8.3/website/source/docs/job-specification/logs.html.md (about)

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