<a id="command-juju-debug-log"></a>

# `juju debug-log`

> See also: [status](https://documentation.ubuntu.com/juju/3.6/reference/status.md#status), [ssh](https://documentation.ubuntu.com/juju/3.6/reference/juju-cli/list-of-juju-cli-commands/ssh.md)

## Summary

Displays log messages for a model.

## Usage

`juju debug-log [options] `

### Options

| Flag                       | Default   | Usage                                                                      |
|----------------------------|-----------|----------------------------------------------------------------------------|
| `-B`, `--no-browser-login` | false     | Do not use web browser for authentication                                  |
| `--color`                  | false     | Force use of ANSI color codes                                              |
| `--date`                   | false     | Show dates as well as times                                                |
| `--exclude-label`          |           | Do not show log messages for these logging labels                          |
| `--exclude-module`         |           | Do not show log messages for these logging modules                         |
| `-i`, `--include`          |           | Only show log messages for these entities                                  |
| `--include-label`          |           | Only show log messages for these logging labels                            |
| `--include-module`         |           | Only show log messages for these logging modules                           |
| `-l`, `--level`            |           | Log level to show, one of [TRACE, DEBUG, INFO, WARNING, ERROR]             |
| `--limit`                  | 0         | Show this many of the most recent logs and then exit                       |
| `--location`               | false     | Show filename and line numbers                                             |
| `-m`, `--model`            |           | Model to operate in. Accepts [<controller name>:]<model name>|<model UUID> |
| `--ms`                     | false     | Show times to millisecond precision                                        |
| `-n`, `--lines`            | 0         | Show this many of the most recent lines and continue to append new ones    |
| `--no-tail`                | false     | Show existing log messages and then exit                                   |
| `--replay`                 | false     | Show the entire log and continue to append new ones                        |
| `--retry`                  | false     | Retry connection on failure                                                |
| `--retry-delay`            | 1s        | Retry delay between connection failure retries                             |
| `--tail`                   | false     | Show existing log messages and continue to append new ones                 |
| `--utc`                    | false     | Show times in UTC                                                          |
| `-x`, `--exclude`          |           | Do not show log messages for these entities                                |

## Examples

Begin with all the log messages:

```none
juju debug-log --replay
```

Begin with the last 500 lines, using grep as a text filter:

```none
juju debug-log -n 500 | grep amd64
```

Begin with the last 30 log messages:

```none
juju debug-log -n 30
```

Begin with the last 20 log messages for the ‘lxd-pilot’ model:

```none
juju debug-log -m lxd-pilot -n 20
```

Begin with the last 1000 lines and exclude messages from machine 3:

```none
juju debug-log -n 1000 --exclude machine-3
```

Select all the messages emitted from a particular unit (you can also write it as
`mysql/0`) and a particular machine in the entire log:

juju debug-log –replay –include unit-mysql-0 –include machine-1

View all WARNING and ERROR messages in the entire log:

```none
juju debug-log --replay --level WARNING
```

View all WARNING and ERROR messages and then continue showing any
new WARNING and ERROR messages as they are logged:

```none
juju debug-log --replay --level WARNING
```

View all logs on the `cmr` topic (label):

```none
juju debug-log --include-label cmr
```

Progressively exclude more content from the entire log:

```none
juju debug-log --replay --exclude-module juju.state.apiserver
juju debug-log --replay --exclude-module juju.state
juju debug-log --replay --exclude-module juju
```

Begin with the last 2000 lines and include messages pertaining to both the
`juju.cmd` and the `juju.worker modules`:

```none
juju debug-log --lines 2000 \
    --include-module juju.cmd \
    --include-module juju.worker
```

Exclude all messages from machine 0 ; show a maximum of 100 lines; and continue to
append filtered messages:

```none
juju debug-log --exclude machine-0 --lines 100
```

Include only messages from the `mysql/0` unit; show a maximum of 50 lines; and then
exit:

```none
juju debug-log --include mysql/0 --limit 50
```

Show all messages from the `apache/2` unit or machine 1 and then exit:

```none
juju debug-log --replay --include apache/2 --include machine-1 --no-tail
```

Show all `juju.worker.uniter` logging module messages that are also unit
`wordpress/0` messages, and then show any new log messages which match the
filter and append:

```none
juju debug-log --replay
    --include-module juju.worker.uniter \
    --include wordpress/0
```

Show all messages from the `juju.worker.uniter` module, except those sent from
`machine-3` or `machine-4`, and then stop:

```none
juju debug-log --replay --no-tail
    --include-module juju.worker.uniter \
    --exclude machine-3 \
    --exclude machine-4
```

## Details

This command provides access to all logged Juju activity on a per-model
basis. By default, the logs for the currently select model are shown.

Each log line is emitted in this format:

```none
<entity> <timestamp> <log-level> <module>:<line-no> <message>
```

The `<entity>`is the source of the message: a machine or a unit. The names for
machines and units can be seen in the output of `juju status`.

The `--include` and `--exclude` options filter by entity. The entity can be
a machine, unit, or application for VM models, but can be application only
for Kubernetes models. These filters support wildcards `*` if filtering on the
entity full name (prefixed by `<entity type>-`).

The `--include-module` and `--exclude-module` options filter by the (dotted)
logging module name. The module name can be truncated such that all loggers
with the prefix will match.

The `--include-label` and `--exclude-label` options filter by logging label.

The filtering options combine as follows:

* All `--include` options are logically ORed together.
* All `--exclude` options are logically ORed together.
* All `--include-module` options are logically ORed together.
* All `--exclude-module` options are logically ORed together.
* All `--include-label` options are logically ORed together.
* All `--exclude-label` options are logically ORed together.
* The combined `--include`, `--exclude`, `--include-module`, `--exclude-module`,
  `--include-label` and `--exclude-label` selections are logically ANDed to form
  the complete filter.

The `--tail` option waits for and continuously prints new log lines after displaying the most recent log lines.

The `--no-tail` option displays the most recent log lines and then exits immediately.

The `--lines` and `--limit` options control the number of log lines displayed:

* the `--lines` option prints the specified number of the most recent lines and then waits for new lines. This implies –tail.
* the `--limit` option prints up to the specified number of the most recent lines and exits. This implies –no-tail.
* setting `--lines` or `--limit` to 0 will print the maximum number of the most recent lines available.
* the maximum value for `--lines` and `--limit` is 10,000. Requests above this limit return an error.

The `--replay` option displays log lines starting from the beginning.

Behavior when combining `--replay` with other options:

* `--replay` and `--limit` prints the specified number of lines from the beginning of the log.
* `--replay` and `--lines` is invalid as it causes confusion by skipping logs between the replayed lines and the current tailing point.

Given the above, the following flag combinations are incompatible and cannot be specified together:

* `--tail` and `--no-tail`
* `--tail` and `--limit`
* `--no-tail` and `--lines (-n)`
* `--limit` and `--lines (-n)`
* `--replay` and `--lines (-n)`
