---
schema_version: "1"
id: 8c61d28717c61c665c5ac118ac4dc62c88e8c5ed7b7d00fb59d3fb808d25ec40
title: apex get log
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforcedx/sfclireference/guides/apex/cli_reference_apex_get_log.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-cli-reference/guide/cli_reference_apex_get_log.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: b5aeeff125864b2059bb0aaa2dbcadff7d62adb23854319a5c1439d26026afa3
products:
  - Salesforce CLI Command Reference
  - salesforcedx
---
<!-- prettier-ignore-start -->

# apex get log

Fetch the specified log or given number of most recent logs from the org.

## Description for apex get log

To get the IDs for your debug logs, run "sf apex log list". Executing this command without flags returns the most recent log.

## Aliases for apex get log

`force:apex:log:get`

## Flags

| Flag Name (Long) | Flag Name (Short) | Description |
|------------------|-------------------|-------------|
| <code>&#8209;&#8209;api&#8209;version</code> | N/A | **Type:** Value<br><br>Override the api version used for api requests made by this command |
| <code>&#8209;&#8209;flags&#8209;dir</code> | N/A | **Type:** Value<br><br>Import flag values from a directory. |
| <code>&#8209;&#8209;json</code> | N/A | **Type:** Boolean<br><br>Format output as json. |
| <code>&#8209;&#8209;log&#8209;id</code> | <code>&#8209;i</code> | **Type:** Value<br><br>ID of the specific log to display. |
| <code>&#8209;&#8209;number</code> | <code>&#8209;n</code> | **Type:** Value<br><br>Number of the most recent logs to display. |
| <code>&#8209;&#8209;output&#8209;dir</code> | <code>&#8209;d</code> | **Type:** Value<br><br>Directory for saving the log files.<br><br>The location can be an absolute path or relative to the current working directory. The default is the current directory. |
| <code>&#8209;&#8209;target&#8209;org</code> | <code>&#8209;o</code> | **Type:** Value<br>**Required**<br><br>Username or alias of the target org. Not required if the `target-org` configuration variable is already set. |

## Examples for apex get log

Fetch the log in your default org using an ID:

```shell
sf apex get log --log-id <log id>
```

Fetch the log in the org with the specified username using an ID:

```shell
sf apex get log --log-id <log id> --target-org me@my.org
```

Fetch the two most recent logs in your default org:

```shell
sf apex get log --number 2
```

Similar to previous example, but save the two log files in the specified directory:

```shell
sf apex get log --output-dir /Users/sfdxUser/logs --number 2
```
<!-- prettier-ignore-end -->
