logging.md 3.67 KB
Newer Older
Patrick von Platen's avatar
Patrick von Platen committed
1
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
Nathan Lambert's avatar
Nathan Lambert committed
2
3
4
5
6
7
8
9
10
11
12

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->

Patrick von Platen's avatar
Patrick von Platen committed
13
# Logging
Nathan Lambert's avatar
Nathan Lambert committed
14

Steven Liu's avatar
Steven Liu committed
15
🤗 Diffusers has a centralized logging system to easily manage the verbosity of the library. The default verbosity is set to `WARNING`.
Nathan Lambert's avatar
Nathan Lambert committed
16

Steven Liu's avatar
Steven Liu committed
17
To change the verbosity level, use one of the direct setters. For instance, to change the verbosity to the `INFO` level.
Nathan Lambert's avatar
Nathan Lambert committed
18

Patrick von Platen's avatar
Patrick von Platen committed
19
20
```python
import diffusers
Nathan Lambert's avatar
Nathan Lambert committed
21

Patrick von Platen's avatar
Patrick von Platen committed
22
23
24
25
26
27
28
29
30
31
32
diffusers.logging.set_verbosity_info()
```

You can also use the environment variable `DIFFUSERS_VERBOSITY` to override the default verbosity. You can set it
to one of the following: `debug`, `info`, `warning`, `error`, `critical`. For example:

```bash
DIFFUSERS_VERBOSITY=error ./myprogram.py
```

Additionally, some `warnings` can be disabled by setting the environment variable
Steven Liu's avatar
Steven Liu committed
33
`DIFFUSERS_NO_ADVISORY_WARNINGS` to a true value, like `1`. This disables any warning logged by
Patrick von Platen's avatar
Patrick von Platen committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[`logger.warning_advice`]. For example:

```bash
DIFFUSERS_NO_ADVISORY_WARNINGS=1 ./myprogram.py
```

Here is an example of how to use the same logger as the library in your own module or script:

```python
from diffusers.utils import logging

logging.set_verbosity_info()
logger = logging.get_logger("diffusers")
logger.info("INFO")
logger.warning("WARN")
```


Steven Liu's avatar
Steven Liu committed
52
All methods of the logging module are documented below. The main methods are
Patrick von Platen's avatar
Patrick von Platen committed
53
[`logging.get_verbosity`] to get the current level of verbosity in the logger and
54
[`logging.set_verbosity`] to set the verbosity to the level of your choice.
Steven Liu's avatar
Steven Liu committed
55
56
57
58
59
60
61
62
63
64
65
66

In order from the least verbose to the most verbose:

|                                                    Method | Integer value |                                         Description |
|----------------------------------------------------------:|--------------:|----------------------------------------------------:|
| `diffusers.logging.CRITICAL` or `diffusers.logging.FATAL` |            50 |                only report the most critical errors |
|                                 `diffusers.logging.ERROR` |            40 |                                  only report errors |
|   `diffusers.logging.WARNING` or `diffusers.logging.WARN` |            30 |           only report errors and warnings (default) |
|                                  `diffusers.logging.INFO` |            20 | only report errors, warnings, and basic information |
|                                 `diffusers.logging.DEBUG` |            10 |                              report all information |

By default, `tqdm` progress bars are displayed during model download. [`logging.disable_progress_bar`] and [`logging.enable_progress_bar`] are used to enable or disable this behavior.
Patrick von Platen's avatar
Patrick von Platen committed
67
68
69

## Base setters

70
[[autodoc]] utils.logging.set_verbosity_error
Patrick von Platen's avatar
Patrick von Platen committed
71

72
[[autodoc]] utils.logging.set_verbosity_warning
Patrick von Platen's avatar
Patrick von Platen committed
73

74
[[autodoc]] utils.logging.set_verbosity_info
Patrick von Platen's avatar
Patrick von Platen committed
75

76
[[autodoc]] utils.logging.set_verbosity_debug
Patrick von Platen's avatar
Patrick von Platen committed
77
78
79

## Other functions

80
[[autodoc]] utils.logging.get_verbosity
Patrick von Platen's avatar
Patrick von Platen committed
81

82
[[autodoc]] utils.logging.set_verbosity
Patrick von Platen's avatar
Patrick von Platen committed
83

84
[[autodoc]] utils.logging.get_logger
Patrick von Platen's avatar
Patrick von Platen committed
85

86
[[autodoc]] utils.logging.enable_default_handler
Patrick von Platen's avatar
Patrick von Platen committed
87

88
[[autodoc]] utils.logging.disable_default_handler
Patrick von Platen's avatar
Patrick von Platen committed
89

90
[[autodoc]] utils.logging.enable_explicit_format
Patrick von Platen's avatar
Patrick von Platen committed
91

92
[[autodoc]] utils.logging.reset_format
Patrick von Platen's avatar
Patrick von Platen committed
93

94
[[autodoc]] utils.logging.enable_progress_bar
Patrick von Platen's avatar
Patrick von Platen committed
95

96
[[autodoc]] utils.logging.disable_progress_bar