Skip to content

Commit d17c4dc

Browse files
authored
Merge pull request #136 from moevm/133_setting_up_logging
133_setting_up_logging
2 parents 287f1df + 5b0cf6d commit d17c4dc

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

utils.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
import pytz
55

66
from constants import MIN_SIDE_PADDING, SIDE_WHITE_SPACES, TIMEZONE, TITLE_LEN
7+
import logging
8+
9+
10+
logging.basicConfig(
11+
level=logging.INFO,
12+
format="%(asctime)s - %(levelname)s - %(message)s",
13+
)
714

815

916
class logger:
@@ -14,9 +21,8 @@ def log_title(title: str, title_len: int = TITLE_LEN):
1421
title_len, len(title) + MIN_SIDE_PADDING * 2 + SIDE_WHITE_SPACES * 2
1522
)
1623

17-
print(
18-
f"{SIDE_WHITE_SPACES * ' ' + title + ' ' * SIDE_WHITE_SPACES:=^{final_len}}"
19-
)
24+
formatted = f"{SIDE_WHITE_SPACES * ' ' + title + ' ' * SIDE_WHITE_SPACES:=^{final_len}}"
25+
logging.info(formatted)
2026

2127
@staticmethod
2228
def log_to_csv(csv_name: str, field_names: tuple[str], row: dict | None = None):
@@ -33,20 +39,19 @@ def log_to_csv(csv_name: str, field_names: tuple[str], row: dict | None = None):
3339

3440
@staticmethod
3541
def log_to_stdout(info: dict):
36-
print(info)
42+
logging.info(f"{info}")
3743

3844
@staticmethod
3945
def log_sep():
40-
print("-" * TITLE_LEN)
46+
logging.info("-" * TITLE_LEN)
4147

4248
@staticmethod
4349
def log_error(error: str):
44-
# или использовать logging, как в interface_wrapper
45-
pass
50+
logging.error(error)
4651

4752
@staticmethod
4853
def log_warning(warning: str):
49-
pass
54+
logging.warning(warning)
5055

5156

5257
def parse_time(datetime_str) -> datetime:

0 commit comments

Comments
 (0)