github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/commands/alloc/logs.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: 'Commands: alloc logs'
     4  sidebar_title: logs
     5  description: |
     6    Stream the logs of a task.
     7  ---
     8  
     9  # Command: alloc logs
    10  
    11  **Alias: `nomad logs`**
    12  
    13  The `alloc logs` command displays the log of a given task.
    14  
    15  ## Usage
    16  
    17  ```plaintext
    18  nomad alloc logs [options] <allocation> <task>
    19  ```
    20  
    21  This command streams the logs of the given task in the allocation. If the
    22  allocation is only running a single task, the task name can be omitted.
    23  Optionally, the `-job` option may be used in which case a random allocation from
    24  the given job will be chosen.
    25  
    26  When ACLs are enabled, this command requires a token with the `read-logs`,
    27  `read-job`, and `list-jobs` capabilities for the allocation's namespace.
    28  
    29  ## General Options
    30  
    31  @include 'general_options.mdx'
    32  
    33  ## Logs Options
    34  
    35  - `-stderr`: Display stderr logs.
    36  
    37  - `-verbose`: Display verbose output.
    38  
    39  - `-job`: Use a random allocation from the specified job, preferring a running
    40    allocation.
    41  
    42  - `-f`: Causes the output to not stop when the end of the logs are reached, but
    43    rather to wait for additional output.
    44  
    45  - `-tail`: Show the logs contents with offsets relative to the end of the logs.
    46    If no offset is given, -n is defaulted to 10.
    47  
    48  - `-n`: Sets the tail location in best-efforted number of lines relative to the
    49    end of the logs.
    50  
    51  - `-c`: Sets the tail location in number of bytes relative to the end of the
    52    logs.
    53  
    54  Note that the `-no-color` option applies to Nomad's own output. If the task's
    55  logs include terminal escape sequences for color codes, Nomad will not remove
    56  them.
    57  
    58  ## Examples
    59  
    60  ```shell-session
    61  $ nomad alloc logs eb17e557 redis
    62  foobar
    63  baz
    64  bam
    65  
    66  $ nomad alloc logs -stderr eb17e557 redis
    67  [ERR]: foo
    68  [ERR]: bar
    69  
    70  $ nomad alloc logs -job example
    71  [ERR]: foo
    72  [ERR]: bar
    73  
    74  $ nomad alloc logs -tail -n 2 eb17e557 redis
    75  foobar
    76  baz
    77  
    78  $ nomad alloc logs -tail -f -n 3 eb17e557 redis
    79  foobar
    80  baz
    81  bam
    82  <blocking>
    83  ```
    84  
    85  ## Using Job ID instead of Allocation ID
    86  
    87  Setting the `-job` flag causes a random allocation of the specified job to be
    88  selected. Nomad will prefer to select a running allocation ID for the job, but
    89  if no running allocations for the job are found, Nomad will use a dead
    90  allocation.
    91  
    92  ```plaintext
    93  nomad alloc logs -job <job-id> <task>
    94  ```
    95  
    96  Choosing a specific allocation is useful for debugging issues with a specific
    97  instance of a service. For other operations using the `-job` flag may be more
    98  convenient than looking up an allocation ID to use.