Question: Using a NAMED logger Instead of using the DEFAULT logger, you can create your own NAMED logger. Create a separate logger with its own name

Using a NAMED logger

Instead of using the DEFAULT logger, you can create your own NAMED logger. Create a separate logger with its own name with its own log level and handler. This will allow you to log messages to a file.

NOTE: When opening Logger File Handlers ... make sure to CLOSE them again!!!

Create a new my_logger with the name 'Q8_logger'

 my_logger = logging.getLogger('question8_log')

Use setLevel(...) to set the logging level of my_logger to logging.DEBUG

Create a logging.FileHandler named fh specifying a log filename of CSC221Lab2.log

Use setLevel(...) to set the logging level of fh to logging.ERROR

Create a the following formatter ...

 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

Use setFormatter(...) to set the fh to use formatter

Use addHandler to add the fh file handler to the my_logger

Generate a DEBUG logger message: 'This is a DEBUG message.' to my_logger

Generate an INFO logger message: 'This is an INFO message.' to my_logger

Generate a WARNING logger message: 'This is a WARNING message.' to my_logger

Generate an ERROR logger message: 'This is an ERROR message.' to my_logger

Generate a CRITICAL logger message: 'This is a CRITICAL message.' to my_logger

REFERENCE: https://docs.python.org/3/howto/logging-cookbook.html

See the sample code provided at the REFERENCE provided as a guide: Heading "Using logging in multiple modules"

""" Generate a variety of logging messages to the console and a log file """ import logging

# INSERT YOUR CODE HERE my_logger = logging.getLogger('question8_log')

# CLOSE file handler fh.close()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!