logging.rst 3.11 KB
Newer Older
Sylvain Gugger's avatar
Sylvain Gugger committed
1
2
3
4
5
6
7
8
9
10
11
12
.. 
    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.

Sylvain Gugger's avatar
Sylvain Gugger committed
13
Logging
Sylvain Gugger's avatar
Sylvain Gugger committed
14
-----------------------------------------------------------------------------------------------------------------------
Sylvain Gugger's avatar
Sylvain Gugger committed
15

16
17
18
19
馃 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``.

Sylvain Gugger's avatar
Sylvain Gugger committed
20
21
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.
Sylvain Gugger's avatar
Sylvain Gugger committed
22
23
24
25
26
27

.. code-block:: python

    import transformers
    transformers.logging.set_verbosity_info()

Sylvain Gugger's avatar
Sylvain Gugger committed
28
29
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:
30
31

.. code-block:: bash
Sylvain Gugger's avatar
Sylvain Gugger committed
32

33
34
    TRANSFORMERS_VERBOSITY=error ./myprogram.py

Sylvain Gugger's avatar
Sylvain Gugger committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
All the methods of this logging module are documented below, the main ones are
:func:`transformers.logging.get_verbosity` to get the current level of verbosity in the logger and
:func:`transformers.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:

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

Base setters
Sylvain Gugger's avatar
Sylvain Gugger committed
49
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sylvain Gugger's avatar
Sylvain Gugger committed
50
51
52
53
54
55
56
57
58
59

.. autofunction:: transformers.logging.set_verbosity_error

.. autofunction:: transformers.logging.set_verbosity_warning

.. autofunction:: transformers.logging.set_verbosity_info

.. autofunction:: transformers.logging.set_verbosity_debug

Other functions
Sylvain Gugger's avatar
Sylvain Gugger committed
60
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sylvain Gugger's avatar
Sylvain Gugger committed
61
62
63
64
65
66

.. autofunction:: transformers.logging.get_verbosity

.. autofunction:: transformers.logging.set_verbosity

.. autofunction:: transformers.logging.get_logger
Lysandre Debut's avatar
Lysandre Debut committed
67
68
69

.. autofunction:: transformers.logging.enable_explicit_format

Sylvain Gugger's avatar
Sylvain Gugger committed
70
.. autofunction:: transformers.logging.reset_format