Unverified Commit b87c044c authored by Francesco Saverio Zuppichini's avatar Francesco Saverio Zuppichini Committed by GitHub
Browse files

Usage examples for logger (#15657)



* logger

* Update docs/source/main_classes/logging.mdx
Co-authored-by: default avatarStas Bekman <stas00@users.noreply.github.com>

* Update docs/source/main_classes/logging.mdx
Co-authored-by: default avatarStas Bekman <stas00@users.noreply.github.com>
Co-authored-by: default avatarStas Bekman <stas00@users.noreply.github.com>
parent 2d02f7b2
...@@ -36,11 +36,34 @@ Additionally, some `warnings` can be disabled by setting the environment variabl ...@@ -36,11 +36,34 @@ Additionally, some `warnings` can be disabled by setting the environment variabl
`TRANSFORMERS_NO_ADVISORY_WARNINGS` to a true value, like *1*. This will disable any warning that is logged using `TRANSFORMERS_NO_ADVISORY_WARNINGS` to a true value, like *1*. This will disable any warning that is logged using
[`logger.warning_advice`]. For example: [`logger.warning_advice`]. For example:
```bash ```bash
TRANSFORMERS_NO_ADVISORY_WARNINGS=1 ./myprogram.py 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 All the methods of this logging module are documented below, the main ones are
[`logging.get_verbosity`] to get the current level of verbosity in the logger and [`logging.get_verbosity`] to get the current level of verbosity in the logger and
[`logging.set_verbosity`] to set the verbosity to the level of your choice. In order (from the least [`logging.set_verbosity`] to set the verbosity to the level of your choice. In order (from the least
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment