Python Logging by Michael Driscoll

Python Logging by Michael Driscoll

Author:Michael Driscoll
Language: eng
Format: epub


Chapter 7 - Logging from Multiple Modules

74

1

# minimath.py

2

3

import logging

4

5

module_logger = logging.getLogger(__name__)

6

7

8

def add(x, y):

9

module_logger.info("Adding %s and %s", x, y) 10

return x + y

11

12

def subtract(x, y):

13

return x - y

14

15

def multiply(x, y):

16

return x * y

17

18

def divide(x, y):

19

return x / y

Here, you once again create a logger using the __name__ object and add a quick informational log message to the add() function.

Now you are ready to try running main.py. Give it a try. You should see the following output in your terminal or your IDE’s console: Figure 7. Main terminal output

Here, the name emitted from main.py is __main__ while the name emitted from minimath.py is utils.minimath. The latter is a



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.