import logging from datetime import datetime import os def setup_logging(): log_dir = 'logs' if not os.path.exists(log_dir): os.makedirs(log_dir) current_time = datetime.now().strftime("%Y%m%d_%H%M%S") log_filename = f'{log_dir}/app_log_{current_time}.txt' logging.basicConfig( level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', filename=log_filename, filemode='w' ) console = logging.StreamHandler() console.setLevel(logging.INFO) formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') console.setFormatter(formatter) logging.getLogger('').addHandler(console) logging.info(f"Logging iniciado. Archivo de log: {log_filename}") if __name__ == "__main__": setup_logging()