<jupyter_start><jupyter_text>LoggingSource(s):* https://realpython.com/python-logging/* https://docs.python.org/3/library/logging.htmllogrecord-attributes<jupyter_code>import logging
# Create a custom logger
logger = logging.getLogger(__name__)
# Create handlers
# c_handler = logging.StreamHandler()
# f_handler = logging.FileHandler('app.log')
# c_handler.setLevel(logging.WARNING)
# f_handler.setLevel(logging.ERROR)
# Create formatters and add it to handlers
# c_format = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
# f_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# c_handler.setFormatter(c_format)
# f_handler.setFormatter(f_format)
# Add handlers to the logger
# logger.addHandler(c_handler)
# logger.addHandler(f_handler)
# logger.warning('This is a warning')
# logger.error('This is an error')
name = 'John'
log_file = 'app.log'
log_level = logging.DEBUG

logging.basicConfig(filename=log_file,
                    filemode='w',
                    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    datefmt='%d-%b-%Y %H:%M:%S',
                    level=log_level
                   )  # Can only be called once
a = 5
b = 0

try:
    c = a / b
except ZeroDivisionError as z:
    logger.error("Exception occurred", exc_info=True)
a = '1'
b = 1

try:
    c = a + b
except TypeError as t:
    logger.exception("Cannot add incompatible types")  # Only shows ERROR level
logger.debug('This is an debug message')
logger.info('{}, this info will get logged'.format(name))
logger.warning('This is a warning message')
logger.error('This is an error message')
logger.critical('This is a critical message')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14061592097617664, 'fraction_numerical': 0.002905287623474724, 'mean_word_length': 3.9482758620689653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '417934', 'license': 'MIT', 'n_tokens_mistral': 573, 'n_tokens_neox': 555, 'n_words': 132, 'path': 'notebooks/Logging.ipynb', 'repo_name': 'coatk1/test_code', 'size': '1721'}