open-nomad/website/source/docs/commands/alloc/logs.html.md.erb

89 lines
2.0 KiB
Plaintext
Raw Normal View History

2016-07-25 20:08:39 +00:00
---
layout: "docs"
2018-03-22 17:56:06 +00:00
page_title: "Commands: alloc logs"
sidebar_current: "docs-commands-alloc-logs"
2016-07-25 20:08:39 +00:00
description: >
Stream the logs of a task.
---
2018-03-22 17:56:06 +00:00
# Command: alloc 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
```
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.
#
## General Options
2016-10-28 00:46:20 +00:00
<%= partial "docs/commands/_general_options" %>
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.
* `-verbose`: Display verbose output.
2017-09-27 18:14:37 +00:00
* `-job`: Use a random allocation from the specified job, preferring a running
2016-07-25 20:08:39 +00:00
allocation.
* `-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.
* `-n`: Sets the tail location in best-efforted number of lines relative to the
end of the logs.
* `-c`: Sets the tail location in number of bytes relative to the end of the logs.
## Examples
```
2018-03-22 17:56:06 +00:00
$ 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.
```
2018-03-22 17:56:06 +00:00
nomad alloc logs -job <job-id> <task>
2016-07-25 20:08:39 +00:00
```
This can be useful for debugging a job that has multiple allocations, and it's
not really required to use a specific allocation ID.