import logging

logging.warning('This warning message will be logged!')
logging.info('This is an info message')

import logging

logging.basicConfig(level=logging.INFO)
logging.info('This will be logged')

import logging

logging.basicConfig(filename='log.txt')
logging.warning('This will get logged to a file')

import logging

logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S')
logging.warning('User logged in')

import threading
import logging

logging.basicConfig(format='%(levelname)s %(threadName)s: Ceci est le %(message)s-ième message du %(threadName)s', filename='output.log', level=logging.DEBUG)

def worker(n):
    for i in range( n+1 ):
        logging.debug(i)
    
t = threading.Thread(name='thread1', target=worker, args=(100000,))
s = threading.Thread(name='thread2', target=worker, args=(50000,))
t.start()
s.start()

import logging

logging.basicConfig(level=logging.DEBUG)

phrase = 'Programmez est le seul magazine écrit par et pour les développeurs'
logging.debug(f'Votre phrase contient {len(phrase)} caractères')

import logging
a, b = 100, 0
try:
  c = a / b
except Exception as e:
  logging.error(f"Exception occurred: {e}")

import logging
a, b = 100, 0
try:
  c = a / b
except Exception as e:
  logging.error(f"Exception occurred: {e}", exc_info=True)

# birthdatemodule.py

from datetime import datetime
from typing import Optional
import logging

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s:%(message)s')
logger = logging.getLogger(__name__)

def get_birth_date(date) -> Optional[datetime]:
    if date:
        try:
            return (date if isinstance(date, datetime)
                    else datetime.strptime(date, '%Y-%m-%d'))
        except ValueError:
            logger.debug(f"{date} is not in the format yyyy-mm-dd. Will try to convert it to the format yyyy/mm/dd")
            try:
                return datetime.strptime(date, '%Y/%m/%d')
            except ValueError:
                logger.debug(f"Unable to convert date. Should be in format yyyy-mm-dd or yyyy/mm/dd")
            return

# save_data_users

import re
import logging
import birthdatemodule

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s% (name)s %(levelname)s:%(message)s')
logger = logging.getLogger(__name__)

FILES = ('Python_users.txt', 'C#_users.txt')

def save_users_data():
    logger.info("starting users data processing")
    for file in FILES:
        try:
            with open(file[:-4] + '.csv', 'a') as csv_file:
                print(*['Birthdate', 'User'], file=csv_file)
                try:
                    with open(file, 'r') as txt_file:
                        logger.info(f"reading {file}")
                        i = 0
                        for line in txt_file:
                            data = get_users_data(line)
                            print(*data, file=csv_file)
                            i += 1
                    logger.debug(f"finish processing {i} users for the file {file}")
                except OSError as e:
                    logger.error(f"error reading the file {e}")
        except:
            logger.warning(f"The file {file} doesn't exist")
        finally:
            logger.debug(f"The function is executed for the file {file}")
def get_users_data(line):
    line = line.rstrip()
    user_name = re.findall('([a-zA-Z]+)\s', line)
    d = re.findall('([0-9].*)', line)[0]
    date = birthdatemodule.get_birth_date(d)
    return [date, user_name]

if __name__ == "__main__":
    save_users_data()