Ignorar el módulo de registro de importación en python

Ejemplos de código

1
0

ignorar el módulo de registro de importación en python

------------ [REASON] ------------
# The problem is that calling getLogger without arguments returns the root logger
# so when you set the level to logging.DEBUG you are also setting the level for
# other modules that use that logger.

------------ [PREVIOUSLY] ------------
## so instead of this
import logging
log_format = "%(levelname)s|%(asctime)s|%(message)s"
logging.basicConfig(filename='monitor_model.log',
					level=logging.DEBUG, format=log_format,
					datefmt="%Y-%m-%d %H:%M:%S")


------------ [NEW] ------------
## do this
#						       __________ it will get the module name
# logger config               ↓
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

# log format
log_format = logging.Formatter("%(levelname)s|%(name)s|%(asctime)s|%(message)s")
# 												↑_____ add module name in log
# file handler
file_handler = logging.FileHandler('monitor_model.log')
file_handler.setFormatter(log_format)
logger.addHandler(file_handler)

# now you can use logger (eg)
logger.info(f'this is some message')

Páginas relacionadas

Páginas de ejemplo relacionadas

En otros idiomas

Esta página está en otros idiomas

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................