<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Basic component
Logger
Step1:  Rotating Log Files
Step2:  The most current file is always logging_rotatingfile_example.out, and each time it reaches the size limit it is renamed with the suffix .1. Each of the existing backup files is renamed to increment the suffix (.1 becomes .2, etc.) and the .5 file is erased.
Verbosity Levels
Another useful feature of the logging API is the ability to produce different messages at different log levels. This means code can be instrumented with debug messages, for example, and the log level can be set so that those debug messages are not written on a production system. the table below lists the logging levels defined by logging.
<table border="1" class="docutils" id="id3">
<caption><span class="caption-text">Logging Levels</span><a class="headerlink" href="#id3" title="Permalink to this table">¶</a></caption>
<colgroup>
<col width="62%" />
<col width="38%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Level</th>
<th class="head">Value</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>CRITICAL</td>
<td>50</td>
</tr>
<tr class="row-odd"><td>ERROR</td>
<td>40</td>
</tr>
<tr class="row-even"><td>WARNING</td>
<td>30</td>
</tr>
<tr class="row-odd"><td>INFO</td>
<td>20</td>
</tr>
<tr class="row-even"><td>DEBUG</td>
<td>10</td>
</tr>
<tr class="row-odd"><td>UNSET</td>
<td>0</td>
</tr>
</tbody>
</table>
Naming Logger Instances
All of the previous log messages all have ‘root’ embedded in them because the code uses the root logger. An easy way to tell where a specific log message comes from is to use a separate logger object for each module. Log messages sent to a logger include the name of that logger. Here is an example of how to log from different modules so it is easy to trace the source of the message.
Step3:  Integration with the warnings Module
The logging module integrates with warnings through captureWarnings(), which configures warnings to send messages through the logging system instead of outputting them directly.
Step4:  Multiple Handlers
<ASSISTANT_TASK:>
Python Code:
import logging
LOG_FILENAME = 'logging_example.log'
logging.basicConfig(
    filename=LOG_FILENAME,
    level=logging.DEBUG,
)
logging.debug('This message should go to the log file')
with open(LOG_FILENAME, 'rt') as f:
    body = f.read()
print('FILE:')
print(body)
Explanation: Basic component
Logger: A named bucket to which messages can be written for processing
LogRecord: Created by Logger.
Formatter: turn the information in log records into output messages.
Filter: provide additional control over which log records are passed from logger to handler
Handler: Engines that determine what happen to each message in a Logger.
Logging to a File
Most applications are configured to log to a file. Use the basicConfig() function to set up the default handler so that debug messages are written to a file.
End of explanation
import glob
import logging
import logging.handlers
LOG_FILENAME = 'logging_rotatingfile_example.log'
# Set up a specific logger with our desired output level
my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)
# Add the log message handler to the logger
handler = logging.handlers.RotatingFileHandler(
    LOG_FILENAME,
    maxBytes=20,
    backupCount=5,
)
my_logger.addHandler(handler)
# Log some messages
for i in range(20):
    my_logger.debug('i = %d' % i)
# See what files are created
logfiles = glob.glob('%s*' % LOG_FILENAME)
for filename in logfiles:
    print(filename)
Explanation: Rotating Log Files
End of explanation
import logging
logging.basicConfig(level=logging.WARNING)
logger1 = logging.getLogger('package1.module1')
logger2 = logging.getLogger('package2.module2')
logger1.warning('This message comes from one module')
logger2.warning('This comes from another module')
Explanation: The most current file is always logging_rotatingfile_example.out, and each time it reaches the size limit it is renamed with the suffix .1. Each of the existing backup files is renamed to increment the suffix (.1 becomes .2, etc.) and the .5 file is erased.
Verbosity Levels
Another useful feature of the logging API is the ability to produce different messages at different log levels. This means code can be instrumented with debug messages, for example, and the log level can be set so that those debug messages are not written on a production system. the table below lists the logging levels defined by logging.
<table border="1" class="docutils" id="id3">
<caption><span class="caption-text">Logging Levels</span><a class="headerlink" href="#id3" title="Permalink to this table">¶</a></caption>
<colgroup>
<col width="62%" />
<col width="38%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Level</th>
<th class="head">Value</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>CRITICAL</td>
<td>50</td>
</tr>
<tr class="row-odd"><td>ERROR</td>
<td>40</td>
</tr>
<tr class="row-even"><td>WARNING</td>
<td>30</td>
</tr>
<tr class="row-odd"><td>INFO</td>
<td>20</td>
</tr>
<tr class="row-even"><td>DEBUG</td>
<td>10</td>
</tr>
<tr class="row-odd"><td>UNSET</td>
<td>0</td>
</tr>
</tbody>
</table>
Naming Logger Instances
All of the previous log messages all have ‘root’ embedded in them because the code uses the root logger. An easy way to tell where a specific log message comes from is to use a separate logger object for each module. Log messages sent to a logger include the name of that logger. Here is an example of how to log from different modules so it is easy to trace the source of the message.
End of explanation
import logging
import warnings
logging.basicConfig(
    level=logging.INFO,
)
warnings.warn('This warning is not sent to the logs')
logging.captureWarnings(True)
warnings.warn('This warning is sent to the logs')
Explanation: Integration with the warnings Module
The logging module integrates with warnings through captureWarnings(), which configures warnings to send messages through the logging system instead of outputting them directly.
End of explanation
import logging
file_hanlder = logging.FileHandler("file_1.log", mode='a', encoding=None, delay=False)
file_hanlder_2 = logging.FileHandler("file_2.log", mode='a', encoding=None, delay=False)
logger = logging.getLogger("mytestlogger")
logger.addHandler(file_hanlder)
logger.addHandler(file_hanlder_2)
logger.critical("test critical message")
Explanation: Multiple Handlers
End of explanation
<END_TASK>