File size: 5,473 Bytes
17c6d62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!--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.

⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.

-->

# λ‘œκΉ… [[logging]]

πŸ€— νŠΈλžœμŠ€ν¬λ¨ΈλŠ” 쀑앙 집쀑식 λ‘œκΉ… μ‹œμŠ€ν…œμ„ μ œκ³΅ν•˜μ—¬ 라이브러리의 좜λ ₯ λ ˆλ²¨μ„ μ‰½κ²Œ μ„€μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

ν˜„μž¬ 라이브러리의 κΈ°λ³Έ 좜λ ₯ λ ˆλ²¨μ€ `WARNING`으둜 μ„€μ •λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

좜λ ₯ λ ˆλ²¨μ„ λ³€κ²½ν•˜λ €λ©΄ 직접적인 μ„€μ • λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, 좜λ ₯ λ ˆλ²¨μ„ INFO μˆ˜μ€€μœΌλ‘œ λ³€κ²½ν•˜λŠ” 방법은 λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

```python
import transformers

transformers.logging.set_verbosity_info()
```

ν™˜κ²½ λ³€μˆ˜ `TRANSFORMERS_VERBOSITY`λ₯Ό μ‚¬μš©ν•˜μ—¬ κΈ°λ³Έ 좜λ ₯ λ ˆλ²¨μ„ μž¬μ •μ˜ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. 이λ₯Ό `debug`, `info`, `warning`, `error`, `critical`, `fatal` 쀑 ν•˜λ‚˜λ‘œ μ„€μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

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

λ˜ν•œ, 일뢀 `warnings`λŠ” ν™˜κ²½ λ³€μˆ˜ `TRANSFORMERS_NO_ADVISORY_WARNINGS`λ₯Ό 1κ³Ό 같은 true κ°’μœΌλ‘œ μ„€μ •ν•˜μ—¬ λΉ„ν™œμ„±ν™”ν•  수 μžˆμŠ΅λ‹ˆλ‹€. μ΄λ ‡κ²Œ ν•˜λ©΄ [`logger.warning_advice`]λ₯Ό μ‚¬μš©ν•˜μ—¬ 기둝된 κ²½κ³ κ°€ λΉ„ν™œμ„±ν™”λ©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

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

λ‹€μŒμ€ λΌμ΄λΈŒλŸ¬λ¦¬μ™€ λ™μΌν•œ 둜거λ₯Ό μžμ‹ μ˜ λͺ¨λ“ˆμ΄λ‚˜ μŠ€ν¬λ¦½νŠΈμ—μ„œ μ‚¬μš©ν•˜λŠ” 방법에 λŒ€ν•œ μ˜ˆμ‹œμž…λ‹ˆλ‹€.

```python
from transformers.utils import logging

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


이 λ‘œκΉ… λͺ¨λ“ˆμ˜ λͺ¨λ“  λ©”μ„œλ“œλŠ” μ•„λž˜μ— λ¬Έμ„œν™”λ˜μ–΄ 있으며, μ£Όμš” λ©”μ„œλ“œλŠ” ν˜„μž¬ 둜거의 좜λ ₯ μˆ˜μ€€μ„ κ°€μ Έμ˜€λŠ” [`logging.get_verbosity`]와 μ›ν•˜λŠ” 좜λ ₯ μˆ˜μ€€μœΌλ‘œ μ„€μ •ν•˜λŠ” [`logging.set_verbosity`] μž…λ‹ˆλ‹€. 좜λ ₯ μˆ˜μ€€μ€ (κ°€μž₯ 적은 좜λ ₯μ—μ„œ κ°€μž₯ λ§Žμ€ 좜λ ₯ 순으둜) λ‹€μŒκ³Ό κ°™μœΌλ©°, ν•΄λ‹Ή μˆ˜μ€€μ— λŒ€μ‘ν•˜λŠ” μ •μˆ˜ 값은 κ΄„ν˜Έ μ•ˆμ— ν‘œμ‹œλ©λ‹ˆλ‹€.

- `transformers.logging.CRITICAL` λ˜λŠ” `transformers.logging.FATAL` (μ •μˆ«κ°’, 50): κ°€μž₯ μ‹¬κ°ν•œ 였λ₯˜λ§Œ λ³΄κ³ ν•©λ‹ˆλ‹€.
- `transformers.logging.ERROR` (μ •μˆ«κ°’, 40): 였λ₯˜λ§Œ λ³΄κ³ ν•©λ‹ˆλ‹€.
- `transformers.logging.WARNING` λ˜λŠ” `transformers.logging.WARN` (μ •μˆ«κ°’, 30): 였λ₯˜μ™€ 경고만 λ³΄κ³ ν•©λ‹ˆλ‹€. μ΄λŠ” λΌμ΄λΈŒλŸ¬λ¦¬μ—μ„œ 기본으둜 μ‚¬μš©λ˜λŠ” μˆ˜μ€€μž…λ‹ˆλ‹€.
- `transformers.logging.INFO` (μ •μˆ«κ°’, 20): 였λ₯˜, κ²½κ³ , 그리고 기본적인 정보λ₯Ό λ³΄κ³ ν•©λ‹ˆλ‹€.
- `transformers.logging.DEBUG` (μ •μˆ«κ°’, 10): λͺ¨λ“  정보λ₯Ό λ³΄κ³ ν•©λ‹ˆλ‹€.

기본적으둜 λͺ¨λΈ λ‹€μš΄λ‘œλ“œ μ€‘μ—λŠ” `tqdm` μ§„ν–‰ ν‘œμ‹œμ€„μ΄ ν‘œμ‹œλ©λ‹ˆλ‹€. [`logging.disable_progress_bar`]와 [`logging.enable_progress_bar`]λ₯Ό μ‚¬μš©ν•˜μ—¬ 이 λ™μž‘μ„ μˆ¨κΈ°κ±°λ‚˜ λ‹€μ‹œ ν‘œμ‹œν•  수 μžˆμŠ΅λ‹ˆλ‹€.

## `logging` vs `warnings`[[transformers.utils.logging.captureWarnings]]

Pythonμ—λŠ” μ’…μ’… ν•¨κ»˜ μ‚¬μš©λ˜λŠ” 두 κ°€μ§€ λ‘œκΉ… μ‹œμŠ€ν…œμ΄ μžˆμŠ΅λ‹ˆλ‹€. μœ„μ—μ„œ μ„€λͺ…ν•œ `logging`κ³Ό `warnings`μž…λ‹ˆλ‹€. `warnings`λŠ” νŠΉμ • λ²”μ£Όλ‘œ κ²½κ³ λ₯Ό μ„ΈλΆ„ν™”ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, 이미 더 이상 μ‚¬μš©λ˜μ§€ μ•ŠλŠ” κΈ°λŠ₯μ΄λ‚˜ κ²½λ‘œμ— λŒ€ν•΄ `FutureWarning`이 μ‚¬μš©λ˜κ³ , κ³§ μ‚¬μš© 쀑단될 κΈ°λŠ₯을 μ•Œλ¦¬κΈ° μœ„ν•΄ `DeprecationWarning`이 μ‚¬μš©λ©λ‹ˆλ‹€.

트랜슀포머 λΌμ΄λΈŒλŸ¬λ¦¬μ—μ„œλŠ” 두 μ‹œμŠ€ν…œ λͺ¨λ‘λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€. `logging`의 `captureWarnings` λ©”μ„œλ“œλ₯Ό ν™œμš©ν•˜κ³  이λ₯Ό μ‘°μ •ν•˜μ—¬ μœ„μ—μ„œ μ„€λͺ…ν•œ 좜λ ₯ μˆ˜μ€€ μ„€μ •μžλ“€μ„ 톡해 μ΄λŸ¬ν•œ κ²½κ³  λ©”μ‹œμ§€λ“€μ„ 관리할 수 μžˆλ„λ‘ ν•©λ‹ˆλ‹€.

라이브러리 κ°œλ°œμžλŠ” λ‹€μŒκ³Ό 같은 지침을 λ”°λ₯΄λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

- `warnings`λŠ” 라이브러리 κ°œλ°œμžμ™€ `transformers`에 μ˜μ‘΄ν•˜λŠ” 라이브러리 κ°œλ°œμžλ“€μ—κ²Œ μœ λ¦¬ν•©λ‹ˆλ‹€.
- `logging`은 일반적인 ν”„λ‘œμ νŠΈ 라이브러리 κ°œλ°œμžλ³΄λ‹€λŠ”, 라이브러리λ₯Ό μ‚¬μš©ν•˜λŠ” μ΅œμ’… μ‚¬μš©μžλ“€μ—κ²Œ μœ λ¦¬ν•  κ²ƒμž…λ‹ˆλ‹€.

μ•„λž˜μ—μ„œ `captureWarnings` λ©”μ†Œλ“œμ— λŒ€ν•œ μ°Έκ³  사항을 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

[[autodoc]] logging.captureWarnings

## κΈ°λ³Έ μ„€μ •μž [[transformers.utils.logging.set_verbosity_error]]

[[autodoc]] logging.set_verbosity_error

[[autodoc]] logging.set_verbosity_warning

[[autodoc]] logging.set_verbosity_info

[[autodoc]] logging.set_verbosity_debug

## 기타 ν•¨μˆ˜ [[transformers.utils.logging.get_verbosity]]

[[autodoc]] logging.get_verbosity

[[autodoc]] logging.set_verbosity

[[autodoc]] logging.get_logger

[[autodoc]] logging.enable_default_handler

[[autodoc]] logging.disable_default_handler

[[autodoc]] logging.enable_explicit_format

[[autodoc]] logging.reset_format

[[autodoc]] logging.enable_progress_bar

[[autodoc]] logging.disable_progress_bar