---
local: logging
sections:
- local: transformers.utils.logging.set_verbosity_error
  title: Base setters
- local: transformers.utils.logging.get_verbosity
  title: Other functions
title: Logging
---
<script>
import Tip from "./Tip.svelte";
import Youtube from "./Youtube.svelte";
import Docstring from "./Docstring.svelte";
import CodeBlock from "./CodeBlock.svelte";
import CodeBlockFw from "./CodeBlockFw.svelte";
import DocNotebookDropdown from "./DocNotebookDropdown.svelte";
import IconCopyLink from "./IconCopyLink.svelte";
export let fw: "pt" | "tf"
</script>
<!--Copyright 2020 The HuggingFace Team. All rights reserved.

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.
-->

<h1 id="logging">Logging</h1>

🤗 Transformers has a centralized logging system, so that you can setup the verbosity of the library easily.

Currently the default verbosity of the library is `WARNING`.

To change the level of verbosity, just use one of the direct setters. For instance, here is how to change the verbosity
to the INFO level.

```python
import transformers

transformers.logging.set_verbosity_info()
```

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

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

Additionally, some `warnings` can be disabled by setting the environment variable
`TRANSFORMERS_NO_ADVISORY_WARNINGS` to a true value, like *1*. This will disable any warning that is logged using
`logger.warning_advice()` For example:

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

Here is an example of how to use `logging` in a module:

```python
from transformers.utils import logging

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

Above, a `logger` instance is created from `logging.get_logger(__name__)`. If you want to use `logging` in a script, you shouldn't pass `__name__` to `logging.get_logger`. For example:

```python
from transformers.utils import logging

if __name__ == "__main__":
    logging.set_verbosity_info()
    # leave it empy or use a string
    logger = logging.get_logger()
    logger.info("INFO")
    logger.warning("WARN")
```

All the methods of this logging module are documented below, the main ones are
[logging.get_verbosity()](/docs/transformers/pr_15592/en/main_classes/logging#transformers.utils.logging.get_verbosity) to get the current level of verbosity in the logger and
[logging.set_verbosity()](/docs/transformers/pr_15592/en/main_classes/logging#transformers.utils.logging.set_verbosity) to set the verbosity to the level of your choice. In order (from the least
verbose to the most verbose), those levels (with their corresponding int values in parenthesis) are:

- `transformers.logging.CRITICAL` or `transformers.logging.FATAL` (int value, 50): only report the most
  critical errors.
- `transformers.logging.ERROR` (int value, 40): only report errors.
- `transformers.logging.WARNING` or `transformers.logging.WARN` (int value, 30): only reports error and
  warnings. This the default level used by the library.
- `transformers.logging.INFO` (int value, 20): reports error, warnings and basic information.
- `transformers.logging.DEBUG` (int value, 10): report all information.

By default, `tqdm` progress bars will be displayed during model download. [logging.disable_progress_bar()](/docs/transformers/pr_15592/en/main_classes/logging#transformers.utils.logging.disable_progress_bar) and [logging.enable_progress_bar()](/docs/transformers/pr_15592/en/main_classes/logging#transformers.utils.logging.enable_progress_bar) can be used to suppress or unsuppress this behavior.

<h2 id="transformers.utils.logging.set_verbosity_error">Base setters</h2>

<div class="docstring">

<docstring><name>transformers.utils.logging.set\_verbosity\_error</name><anchor>transformers.utils.logging.set_verbosity_error</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L184</source><parameters>[]</parameters></docstring>
Set the verbosity to the `ERROR` level.

</div>

<div class="docstring">

<docstring><name>transformers.utils.logging.set\_verbosity\_warning</name><anchor>transformers.utils.logging.set_verbosity_warning</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L174</source><parameters>[]</parameters></docstring>
Set the verbosity to the `WARNING` level.

</div>

<div class="docstring">

<docstring><name>transformers.utils.logging.set\_verbosity\_info</name><anchor>transformers.utils.logging.set_verbosity_info</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L169</source><parameters>[]</parameters></docstring>
Set the verbosity to the `INFO` level.

</div>

<div class="docstring">

<docstring><name>transformers.utils.logging.set\_verbosity\_debug</name><anchor>transformers.utils.logging.set_verbosity_debug</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L179</source><parameters>[]</parameters></docstring>
Set the verbosity to the `DEBUG` level.

</div>

<h2 id="transformers.utils.logging.get_verbosity">Other functions</h2>

<div class="docstring">

<docstring><name>transformers.utils.logging.get\_verbosity</name><anchor>transformers.utils.logging.get_verbosity</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L127</source><parameters>[]</parameters><rettype>`int`</rettype><retdesc>The logging level.</retdesc></docstring>

Return the current level for the 🤗 Transformers's root logger as an int.





<Tip>

🤗 Transformers has following logging levels:

- 50: `transformers.logging.CRITICAL` or `transformers.logging.FATAL`
- 40: `transformers.logging.ERROR`
- 30: `transformers.logging.WARNING` or `transformers.logging.WARN`
- 20: `transformers.logging.INFO`
- 10: `transformers.logging.DEBUG`

</Tip>

</div>

<div class="docstring">

<docstring><name>transformers.utils.logging.set\_verbosity</name><anchor>transformers.utils.logging.set_verbosity</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L150</source><parameters>[{"name": "verbosity", "val": ": int"}]</parameters><paramsdesc>- **verbosity** (`int`) --
  Logging level, e.g., one of:

  - `transformers.logging.CRITICAL` or `transformers.logging.FATAL`
  - `transformers.logging.ERROR`
  - `transformers.logging.WARNING` or `transformers.logging.WARN`
  - `transformers.logging.INFO`
  - `transformers.logging.DEBUG`</paramsdesc><paramgroups>0</paramgroups></docstring>

Set the verbosity level for the 🤗 Transformers's root logger.




</div>

<div class="docstring">

<docstring><name>transformers.utils.logging.get\_logger</name><anchor>transformers.utils.logging.get_logger</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L113</source><parameters>[{"name": "name", "val": ": typing.Optional[str] = None"}]</parameters></docstring>

Return a logger with the specified name.

This function is not supposed to be directly accessed unless you are writing a custom transformers module.


</div>

<div class="docstring">

<docstring><name>transformers.utils.logging.enable\_default\_handler</name><anchor>transformers.utils.logging.enable_default_handler</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L198</source><parameters>[]</parameters></docstring>
Enable the default handler of the HuggingFace Transformers's root logger.

</div>

<div class="docstring">

<docstring><name>transformers.utils.logging.disable\_default\_handler</name><anchor>transformers.utils.logging.disable_default_handler</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L189</source><parameters>[]</parameters></docstring>
Disable the default handler of the HuggingFace Transformers's root logger.

</div>

<div class="docstring">

<docstring><name>transformers.utils.logging.enable\_explicit\_format</name><anchor>transformers.utils.logging.enable_explicit_format</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L244</source><parameters>[]</parameters></docstring>

Enable explicit formatting for every HuggingFace Transformers's logger. The explicit formatter is as follows:
```
    [LEVELNAME|FILENAME|LINE NUMBER] TIME >> MESSAGE
```
All handlers currently bound to the root logger are affected by this method.


</div>

<div class="docstring">

<docstring><name>transformers.utils.logging.reset\_format</name><anchor>transformers.utils.logging.reset_format</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L259</source><parameters>[]</parameters></docstring>

Resets the formatting for HuggingFace Transformers's loggers.

All handlers currently bound to the root logger are affected by this method.


</div>

<div class="docstring">

<docstring><name>transformers.utils.logging.enable\_progress\_bar</name><anchor>transformers.utils.logging.enable_progress_bar</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L335</source><parameters>[]</parameters></docstring>
Enable tqdm progress bar.

</div>

<div class="docstring">

<docstring><name>transformers.utils.logging.disable\_progress\_bar</name><anchor>transformers.utils.logging.disable_progress_bar</anchor><source>https://github.com/huggingface/transformers/blob/pr_15592/src/transformers/utils/logging.py#L341</source><parameters>[]</parameters></docstring>
Enable tqdm progress bar.

</div>
