Skip to content

Commit

Permalink
docs: add logging user guide [APE-1227] (#1564)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jul 26, 2023
1 parent f02e3ea commit 96fd774
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
userguides/testing
userguides/scripts
userguides/publishing
userguides/logging
```

```{eval-rst}
Expand Down
2 changes: 1 addition & 1 deletion docs/userguides/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Then, add the following to your config so that Ape can find the dependency:
```yaml
dependencies:
- name: MyDependency
npm: @myorg/mydependency
npm: "@myorg/mydependency"
version: v1.3.0
```

Expand Down
49 changes: 49 additions & 0 deletions docs/userguides/logging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Logging

Ape provides a logger and uses it to show messages throughout the execution of its modules.
Every CLI command comes with the logger in Ape, even custom user scripts (unless they change the behavior of `--verbosity`).

The following log levels are available with Ape:

| Log Level | Numeric Value | Purpose | Color |
| --------- | ------------- | ------------------------------ | ------ |
| DEBUG | 10 | Debug stuff | Blue |
| INFO | 20 | General information | Blue |
| SUCCESS | 21 | To mark a successful operation | Green |
| WARNING | 30 | Indicates a potential issue | Yellow |
| ERROR | 40 | An error occurred | Red |

**NOTE**: `SUCCESS` is a non-standard verbosity level custom to the framework.
It is shown during `INFO` but not shown if set to `WARNING` or above.

## CLI Logging

If you are running into issues and wish to see more information logged, you likely want to run your command with `--verbosity DEBUG` or `-v debug`:

```bash
ape --verbosity DEBUG my_cmd # long form
ape -v debug my_cmd # short form
```

This will output HTTP requests and anything else with a `DEBUG` logging verbosity in Ape.

Alternatively, you may wish to log less and show important logs, such as `ERROR` logs.
To do this, use the `ERROR` verbosity:

```bash
ape my_cmd -v ERROR
```

*NOTE*: You can put the verbosity flag anywhere in your CLI command for _most_ commands.

## Python Logging

You can also import and use the logger in your own Python scripts or commands:

```python
from ape.logging import logger, LogLevel

def main():
logger.info("You have entered `main()`.")
logger.set_level(LogLevel.WARNING)
```

0 comments on commit 96fd774

Please sign in to comment.