Apuntes_Python/02_conceptos/10_logging/a_basico.py
2022-12-24 22:41:20 -03:00

28 lines
642 B
Python
Executable File

"""
Logger personalizado
"""
import logging
logger = logging.getLogger(__name__)
# logger.propagate = False
# Crear manejador
stream_h = logging.StreamHandler()
file_h = logging.FileHandler('file.log')
# Nivel y formato
stream_h.setLevel(logging.WARNING)
file_h.setLevel(logging.ERROR)
formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
stream_h.setFormatter(formatter)
file_h.setFormatter(formatter)
# Agregar manejadores a logger
logger.addHandler(stream_h)
logger.addHandler(file_h)
logger.info('Hola desde el modulo helper')
logger.warning('Esta es una advertencia')
logger.error('Este es un msj de error')