Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

ignore module import log in 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')
Comment

PREVIOUS NEXT
Code Example
Python :: absolut beginners projects in python with tutorial 
Python :: typingclub hack python 
Python :: first openfaas python function 
Python :: how to print me me big boy python 
Python :: th2=cv2.adaptiveThreshold(img, 255 ,cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11 # no of block size , 2 #c) 
Python :: neural network without training return same output with random biases 
Python :: creating a new enviroment in conda 
Python :: python list comprehension index, value 
Python :: python gzip 
Python :: pandas datetime to date 
Python :: python test if number in string 
Python :: in pandas series hot to count the numer of appearences 
Python :: python interpreter clear screen 
Python :: print the heat map python 
Python :: SQL Query to Join Two Tables Based Off Closest Timestamp 
Python :: renpy scene vs show 
Python :: last 24 hour python datetime 
Python :: download stopwords nltk 
Python :: create a response object in python 
Python :: python min length list of strings 
Python :: yapf ignore line 
Python :: codeforces - 570b python 
Python :: django q filter 
Python :: how to know if a input is a interger in python 
Python :: python run exe with arguments 
Python :: splittext py 
Python :: django check if user is staff in template 
Python :: python json parse 
Python :: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaple 
Python :: remove duplicate space in string in pytoon 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =