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