github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/commands/alloc/logs.mdx (about)

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