Skip to content

Commit

Permalink
added: Add logging example
Browse files Browse the repository at this point in the history
  • Loading branch information
kmsint committed Feb 8, 2024
1 parent 127e28e commit e8b44c9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 37 deletions.
32 changes: 0 additions & 32 deletions arguments_passing/bot.py

This file was deleted.

8 changes: 6 additions & 2 deletions critical.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#CRITICAL [2024-01-05 18:17:32,384] - Лог CRITICAL
#CRITICAL [2024-01-05 18:17:32,386] - Лог CRITICAL
#CRITICAL [2024-02-05 00:54:52,599] - Вошли в функцию square_number
#CRITICAL [2024-02-05 00:54:52,599] - Лог CRITICAL
#CRITICAL [2024-02-05 00:54:52,599] - Вышли из функции square_number
#CRITICAL [2024-02-05 00:54:52,599] - Вошли в функцию square_number
#CRITICAL [2024-02-05 00:54:52,600] - Лог CRITICAL
#CRITICAL [2024-02-05 00:54:52,600] - Вышли из функции square_number
2 changes: 1 addition & 1 deletion error.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[2024-01-05 18:17:32,380] #ERROR module_1.py:16 - module_1:main - Лог ERROR
[2024-02-05 00:54:52,599] #ERROR module_1.py:53 - module_1:main - Лог ERROR
5 changes: 5 additions & 0 deletions logging_examples/logging_config_example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
format='#%(levelname)-8s %(name)s:%(funcName)s - %(message)s'
)

logger = logging.getLogger(__name__)

handler_main = logging.StreamHandler()
logger.addHandler(handler_main)

# Исполняем функцию `main` из модуля `module_1.py`
main()
7 changes: 6 additions & 1 deletion logging_examples/logging_config_example/module_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def filter(self, record):


def main():

logger.critical('Вошли в функцию %s', main.__name__)

a, b = 12, 2
c, d = 4, 0

Expand All @@ -51,4 +54,6 @@ def main():
logger.critical('Лог CRITICAL')

print(devide_number(a, square_number(b)))
print(devide_number(square_number(c), d))
print(devide_number(square_number(c), d))

logger.critical('Вышли из функции %s', main.__name__)
6 changes: 5 additions & 1 deletion logging_examples/logging_config_example/module_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def filter(self, record):

def devide_number(dividend: int | float, devider: int | float):

logger.critical('Вошли в функцию %s', devide_number.__name__)

logger.debug('Лог DEBUG')
logger.info('Лог INFO')
logger.warning('Лог WARNING')
Expand All @@ -42,4 +44,6 @@ def devide_number(dividend: int | float, devider: int | float):
try:
return dividend / devider
except ZeroDivisionError:
logger.exception('Произошло деление на 0')
logger.exception('Произошло деление на 0')

logger.critical('Вышли из функции %s', devide_number.__name__)
4 changes: 4 additions & 0 deletions logging_examples/logging_config_example/module_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ def filter(self, record):

def square_number(number: int | float):

logger.critical('Вошли в функцию %s', square_number.__name__)

logger.debug('Лог DEBUG')
logger.info('Лог INFO')
logger.warning('Лог WARNING')
logger.error('Лог ERROR')
logger.critical('Лог CRITICAL')

logger.critical('Вышли из функции %s', square_number.__name__)

return number**2

0 comments on commit e8b44c9

Please sign in to comment.