open-nomad/website/pages/docs/commands/alloc/logs.mdx

99 lines
2.4 KiB
Plaintext
Raw Normal View History

2016-07-25 20:08:39 +00:00
---
2020-02-06 23:45:31 +00:00
layout: docs
page_title: 'Commands: alloc logs'
sidebar_title: logs
description: |
2016-07-25 20:08:39 +00:00
Stream the logs of a task.
---
2018-03-22 17:56:06 +00:00
# Command: alloc logs
2018-03-22 18:09:26 +00:00
**Alias: `nomad logs`**
2016-07-25 20:08:39 +00:00
2018-03-22 17:56:06 +00:00
The `alloc logs` command displays the log of a given task.
2016-07-25 20:08:39 +00:00
## Usage
```plaintext
2018-03-22 17:56:06 +00:00
nomad alloc logs [options] <allocation> <task>
2016-07-25 20:08:39 +00:00
```
This command streams the logs of the given task in the allocation. If the
2016-07-25 20:08:39 +00:00
allocation is only running a single task, the task name can be omitted.
Optionally, the `-job` option may be used in which case a random allocation from
the given job will be chosen.
When ACLs are enabled, this command requires a token with the `read-logs`,
`read-job`, and `list-jobs` capabilities for the allocation's namespace.
2016-07-25 20:08:39 +00:00
## General Options
2020-02-06 23:45:31 +00:00
@include 'general_options.mdx'
2016-07-25 20:08:39 +00:00
2016-07-25 20:29:19 +00:00
## Logs Options
2016-07-25 20:08:39 +00:00
- `-stderr`: Display stderr logs.
2016-07-25 20:08:39 +00:00
- `-verbose`: Display verbose output.
2016-07-25 20:08:39 +00:00
- `-job`: Use a random allocation from the specified job, preferring a running
allocation.
2016-07-25 20:08:39 +00:00
- `-f`: Causes the output to not stop when the end of the logs are reached, but
rather to wait for additional output.
2016-07-25 20:08:39 +00:00
- `-tail`: Show the logs contents with offsets relative to the end of the logs.
If no offset is given, -n is defaulted to 10.
2016-07-25 20:08:39 +00:00
- `-n`: Sets the tail location in best-efforted number of lines relative to the
end of the logs.
2016-07-25 20:08:39 +00:00
- `-c`: Sets the tail location in number of bytes relative to the end of the
logs.
2016-07-25 20:08:39 +00:00
Note that the `-no-color` option applies to Nomad's own output. If the task's
logs include terminal escape sequences for color codes, Nomad will not remove
them.
2016-07-25 20:08:39 +00:00
## Examples
2020-05-18 20:53:06 +00:00
```shell-session
$ nomad alloc logs eb17e557 redis
2016-07-25 20:08:39 +00:00
foobar
baz
bam
2018-03-22 17:56:06 +00:00
$ nomad alloc logs -stderr eb17e557 redis
2016-07-25 20:08:39 +00:00
[ERR]: foo
[ERR]: bar
2018-03-22 17:56:06 +00:00
$ nomad alloc logs -job example
2016-07-25 20:08:39 +00:00
[ERR]: foo
[ERR]: bar
2018-03-22 17:56:06 +00:00
$ nomad alloc logs -tail -n 2 eb17e557 redis
2016-07-25 20:08:39 +00:00
foobar
baz
2018-03-22 17:56:06 +00:00
$ nomad alloc logs -tail -f -n 3 eb17e557 redis
2016-07-25 20:08:39 +00:00
foobar
baz
bam
<blocking>
```
## Using Job ID instead of Allocation ID
Setting the `-job` flag causes a random allocation of the specified job to be
selected. Nomad will prefer to select a running allocation ID for the job, but
if no running allocations for the job are found, Nomad will use a dead
allocation.
```plaintext
2018-03-22 17:56:06 +00:00
nomad alloc logs -job <job-id> <task>
2016-07-25 20:08:39 +00:00
```
2019-05-17 17:39:09 +00:00
Choosing a specific allocation is useful for debugging issues with a specific
instance of a service. For other operations using the `-job` flag may be more
convenient than looking up an allocation ID to use.