Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Vi Special Issue On Database And Expert Systems Applications Lncs 7600

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2012th Edition

3642341780, 978-3642341786

More Books

Students also viewed these Databases questions

Question

10. What is meant by a feed rate?

Answered: 1 week ago